-1

I'm trying automate navigation of my account on a website. Because Selenium doesn't store my cookies across sessions, I have to accept the terms of service via a pop up every time. This would be fine, except Selenium is incapable of waiting.

# wait 1 minute
wait = WebDriverWait(driver, 60)

# wait for TOS to appear
wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="tos_agree"]')))

# accept TOS
elem = driver.find_element_by_xpath('//*[@id="tos_agree"]')
elem.click()
elem = driver.find_element_by_xpath('//*[@id="accept_tos"]')
elem.click()

# wait for login window to appear (b/c TOS needs to fade)
wait.until(EC.visibility_of_element_located((By.XPATH, '//*[@id="login-dropdown"]')))

# login
elem = driver.find_element_by_xpath('//*[@id="login-dropdown"]')
elem.click()

The first wait seems to work, but then I get this message.

Message: Element <a id="login-dropdown" class="dropdown-toggle" href="/login"> is not clickable at point (1228.0749740600586,18.5) because another element <h2 class="heading"> obscures it

The stack trace indicates that the error is caused by the last elem.click(). I can also confirm that my program isn't waiting a full minute before crashing.

What's going on and how do I fix it?

alternum5
  • 75
  • 8

1 Answers1

0
# wait for login window to appear (b/c TOS needs to fade)
wait.until(EC.visibility_of_element_located((By.XPATH, '//*[@id="login-dropdown"]')))

The above line will not wait for TOS to fade on all cases. If they use css transition to fade, before transition completes, you are login dropdown will be visible.

Just add an invisiblity wait fpr TOS and try. So you may write like below,

 # wait for TOS to fade)
wait.until(EC.invisibility_of_element_located((By.XPATH, '//*[@id="accept_tos"]')))
# wait for login window to appear
wait.until(EC.visibility_of_element_located((By.XPATH, '//*[@id="login-dropdown"]')))
Navarasu
  • 8,209
  • 2
  • 21
  • 32