ElementNotVisibleException Selenium

0

I'm trying to login 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 not find the email field

and returns the error:

  

ElementNotVisibleException: Message: element not visible

How can I get around this?

    
asked by anonymous 29.11.2016 / 14:08

1 answer

2

The error is very 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 has not yet 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')))

This sets 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 time.sleep (5) into something more functional.

Selenium Waiting Reference: link

    
29.11.2016 / 21:53