Elementnotvisibleexception Selenium

Asked

Viewed 498 times

1

I’m trying to log in to www.pactpub.com

using the following idea

def setUp(self):

    self.driver = webdriver.Chrome(executable_path='C:\_workspace\projects\Packtpub\chromedriver')
    self.driver.get("https://www.packtpub.com")
    time.sleep(5) # Let the user actually see something!


def test_login(self):

    driver = self.driver
    driver.maximize_window()

    login1 = driver.find_element_by_id("email-wrapper")
    login1.find_element_by_id("email").send_keys("my_login")

but he can’t find the email field

and returns the error:

Elementnotvisibleexception: Message: element not Visible

how can I get around?

1 answer

2


The error is quite clear: the element you are trying to select is not visible. This can be caused by some factors such as: the visibility of the element depends on a certain action on the page or the element is simply not finished being loaded.

In any case, you can try to wait until the element is visible, as follows:

from selenium.webdriver.support import expected_conditions as EC

espera = WebDriverWait(driver, 10)
login1 = wait.until(EC.visibility_of((By.ID,'email-wrapper')))

With this you set a limit of up to 10 seconds of waiting until the "email-wrapper" element becomes visible. You can also use this same logic to turn your team.Leep(5) into something more functional.

Reference on waits in Selenium: http://selenium-python.readthedocs.io/waits.html

  • You need to fix the example. No you instantiate the WebDriverWait in the wait variable and below uses a variable wait. In case the wait would be the espera.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.