I want to check the xpath available in the browser or not.
How can i check
xpath = '//img' driver.find_element_by_xpath(xpath).click()
What's the way to check it?
I want to check the xpath available in the browser or not.
How can i check
xpath = '//img' driver.find_element_by_xpath(xpath).click()
What's the way to check it?
You can use it:
xpath = "//img"
if driver.find_elements_by_xpath(xpath):
driver.find_element_by_xpath(xpath).click()
print("xpath found and clicked")
Let's say you have some xpath : //div[@role='some role']
In Selenium I would do this :
try:
if len(driver.find_elements(By.XPATH, "//div[@role='some role']")) > 0:
print("xpath is present")
else:
print("xpath is not present")
except:
pass