J
J
jekakeba2021-12-04 19:57:13
Python
jekakeba, 2021-12-04 19:57:13

Find_element syntax in Selenium 4?

Hello!
Please help me figure it out ...
In the old version, everything was simple and the paycharm suggested) And how is it in the new version? Thank you!
driver.find_element_by_xpath('здесь сам Xpath')

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
ScriptKiddo, 2021-12-04
@jekakeba

https://www.selenium.dev/documentation/getting_sta...
Before

driver.findElementsByClassName("className");
driver.findElementsByCssSelector(".className");
driver.findElementsById("elementId");
driver.findElementsByLinkText("linkText");
driver.findElementsByName("elementName");
driver.findElementsByPartialLinkText("partialText");
driver.findElementsByTagName("elementTagName");
driver.findElementsByXPath("xPath");

After
driver.findElements(By.className("className"));
driver.findElements(By.cssSelector(".className"));
driver.findElements(By.id("elementId"));
driver.findElements(By.linkText("linkText"));
driver.findElements(By.name("elementName"));
driver.findElements(By.partialLinkText("partialText"));
driver.findElements(By.tagName("elementTagName"));
driver.findElements(By.xpath("xPath"));

An example in Java, similar to
By in Python is here
from selenium.webdriver.common.by import By
driver.find_element(By.XPATH, xpath)

S
soremix, 2021-12-04
@SoreMix

As it was, so everything remains. The method takes only two parameters - By and the search string, there is nothing to highlight there

from selenium.webdriver.common.by import By
driver.find_element(By.XPATH, '//button[text()="Some text"]')

https://selenium-python.readthedocs.io/locating-el...
https://www.selenium.dev/documentation/webdriver/l...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question