Not able to use is_displayed property in python selenium

Viewed 321

I want to check if a text(hyperlink) is present or not in the page. If displayed I was click on it. And if not sleep for 5 more seconds.

I've tried

if driver.find_element_by_id('xpath').is_displayed:
    driver.find_element_by_id('xpath').click() 
else:
    time.sleep(2)

However I'm not able to get it to work.

2 Answers

Here it looks like in place of xpath method, you are using id method to find element or vice versa. It should be driver.find_element_by_xpath('xpath')

is_displayed()

is_displayed() method determines whether the element is visible to a user. So essentially your line of code should have been:

if driver.find_element_by_id('xpath').is_displayed():
Related