-1

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?

Roky
  • 21
  • 4
  • Does this answer your question? [Selenium - wait until element is present, visible and interactable](https://stackoverflow.com/questions/59130200/selenium-wait-until-element-is-present-visible-and-interactable) – Prophet Jun 15 '21 at 09:47
  • What do you mean by availability ? – cruisepandey Jun 15 '21 at 09:48
  • You need to give more dateless for proper understanding. Actually what you want to do? – Jawad Jun 15 '21 at 09:49
  • I want to check if Xpath is available in the browser or not. – Roky Jun 15 '21 at 09:55
  • You can go to developer tool in chrome and then element and then CTRL + F and search for your xpath there. If you want to do it programmatically which is not the right approach let me know – cruisepandey Jun 15 '21 at 09:56
  • Yes. I want to do it with selenium. – Roky Jun 15 '21 at 10:04

2 Answers2

2

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")
Jawad
  • 166
  • 7
1

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
cruisepandey
  • 28,520
  • 6
  • 20
  • 38