5

I have been using selenium for a while with these two methods interchangeably.

elem = driver.find_element_by_xpath("some_xpath") elem = driver.find_element(By.XPATH,"some_xpath") 

So far both of them work. I wanted to understand what is the difference in both of them.

https://selenium-python.readthedocs.io/locating-elements.html Documentation mentions By.XPATH as private method, but did not understand it clearly.

1 Answer 1

7

find_element_by_xpath('xpath') calls find_element(By.XPATH,'xpath'), so actually there is no real difference.

From github

def find_element_by_xpath(self, xpath): return self.find_element(by=By.XPATH, value=xpath) 

As of Selenium 4.3, the find_element_by_* and find_elements_by_* methods are deprecated. See the Selenium change log.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.