1

I have this page. I have to click on Facebook icon. Upon doing it I m getting:

selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with

Code is given below:

if 'log' in html.lower():
        print("not logged in")
        sleep(3)
        #Click on Fb button
        fb_element = driver.find_element_by_xpath('//a[@tooltip="Facebook"]')
        fb_element.vis
        fb_element.send_keys(Keys.TAB)

1 Answer 1

1

There is an another element with tooltip="Facebook" on the page and this element is actually invisible. Well, there are actually 10 of them:

> $x('//a[@tooltip="Facebook"]').length
10

You can find find all elements matching your locator and filter the visible one via next() and is_displayed():

facebook_links = driver.find_elements_by_xpath('//a[@tooltip="Facebook"]')
visible_link = next(link for link in facebook_links if link.is_displayed())
visible_link.click()
Sign up to request clarification or add additional context in comments.

2 Comments

Ah - So my assumption to have only one such element was wrong. Your code worked like charm. Thanks!
@Volatil3 yeah, I've also briefly tried to narrow down the locator to make it uniquely identify the desired link, but I've got 5 instead of 10 at best with my attempts. Filter visible only does not sound like a bad idea in this case :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.