1

I am using python with Selenium WebDriver to test an angular based web-app.

In the login helper subroutine, on login, I want to check if it was successful before continuing with rest of the tests.

For this , I have the following piece of code:

login_success = WebDriverWait(self.driver,5).until(EC.visibility_of_element_located((By.CLASS_NAME,"hr-landing")))

if login_success:
    self.logger.info("Looks like login was successful")
else:
    login_errors = self.get_login_errors()
    self.logger.debug(login_errors)

The problem I am facing is with the first line in the code. For a successful login, it returns quickly as the class 'hr-landing' is found.

However, for a failed login, that class is not found , and I wish for the Wait to timeout in 5 seconds as specified in my call to WebDriverWait.

However, the call times out only after 30 seconds (which is the implicit wait I have set on my driver)

How can I get around this issue ? I feel there is no point to providing the explicit timeout , because it is still respecting the implicit one.

Thanks a lot ! Moez.

  • get_login_errors contain implicity waits? – murali selenium Apr 06 '16 at 06:52
  • I call self.driver.implicitly_wait(30) once at beginning of the test harness -- and that wait setting is persisting in my login methods -- not only persisting , but it is given priority over the explicit wait provided to WebDriverWait – Moez Hirani Apr 06 '16 at 16:15

1 Answers1

0

This is the issue generally we face when both implicit and explicit waits are used. On fail get_login_errors() is called so i am expecting it have implicit waits.

To avoid such issues i hope good to use fluent waits which explained here

Thank You, Murali

Community
  • 1
  • 1
murali selenium
  • 3,847
  • 2
  • 11
  • 20
  • Is there a python equivalent to fletnwait? – Moez Hirani Apr 06 '16 at 16:15
  • Hi looks like fluentwait is not available in python. in same link there is way in python to check elements by explicit wait. def conditions(driver): flag = True ticker = driver.find_elements_by_id("textbox") if not ticker: flag = False return flag ... click something to load ... self.wait = WebDriverWait(driver, timeout) self.wait.until(conditions) – murali selenium Apr 06 '16 at 16:34