Reputation: 111
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.
Upvotes: 5
Views: 2054
Reputation: 50809
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.
Upvotes: 7