Search code examples
pythonseleniumsplinter

How to click an invisible element with selenium?


i used this code to check splinter's clicking button option:

from splinter import Browser

    with Browser() as browser:
    # Visit URL
    url = "http://www.google.com"
    browser.visit(url)
    browser.fill('q', 'splinter - python acceptance testing for web applications')
    # Find and click the 'search' button
    button = browser.find_by_name('btnG')
    # Interact with elements
    button.click()
    if browser.is_text_present('splinter.readthedocs.org'):
        print("Yes, the official website was found!")
    else:
        print("No, it wasn't found... We need to improve our SEO techniques")

and i got exception: Element is not currently visible ans so may not be interacted. waiting for the browser is not the solution (becuase i made sleep method for long time and still doesnt work). this is sample code shown in https://splinter.readthedocs.org/en/latest/#sample-code , but is doesnt work for me


Solution

  • If you want to wait for an element to become invisible, you can use wait function:

        wait = WebDriverWait(self.driver, 30)
        wait.until(EC.invisibility_of_element_located((By.XX, "something")))