I have a situation where I am testing some stuff with selenium webdriver. When trying to log in to OneDrive the driver ignores all waits and I get "element not visible error", Specifically for the page where you input the password. This only happens in this situation and the rest of the instances where I use pretty much the same code to run the login process on several pages work fine.
This is the code corresponding to the failing code
def selenium_onedrive(loading_done_event, selenium, user, psw):
loading_done_event.wait()
login = selenium.find_elements_by_name('loginfmt')[0]
login.send_keys(user)
next_step = selenium.find_element_by_id('idSIButton9')
next_step.click()
password = WebDriverWait(selenium, 10).until(
# EC.presence_of_element_located((By.NAME, "passwd"))
EC.element_to_be_clickable((By.ID, "i0118"))
)
**password.send_keys(psw)**
# password.submit()
next_step = selenium.find_element_by_id('idSIButton9')
next_step.click()
The bold line is the one where the error ocurs. It says element could not be found but the waits (even implicit ones) are ignored.
And this is an example of a login code that works
def selenium_gdrive(loading_done_event, selenium, user, psw):
loading_done_event.wait()
login = selenium.find_elements_by_name('Email')[0]
login.send_keys(user)
selenium.find_elements_by_name('signIn')[0].click()
password = WebDriverWait(selenium, 10).until(
EC.presence_of_element_located((By.NAME, "Passwd"))
)
password.send_keys(psw)
password.submit()
# now we will be navigated to the consent page
consent_accept_button = WebDriverWait(selenium, 10).until(
EC.element_to_be_clickable((By.ID, "submit_approve_access"))
)
consent_accept_button.click()
Additional info, running the code with Firefox driver. If I use the Chrome version it runs fine but it's unstable and get random "connection ended remotedly"
I noticed that it wasn't loading a new page but dynamically changing the contents of the form to show different fields for each step. Wasn't sure how to treat this properly so I had to use time.sleep(1) to wait for the contents to load and the code to locate the new elements. I know it's not the best way but for now is the only workaround I've found.
Final Code
def selenium_onedrive(loading_done_event, selenium, user, psw):
loading_done_event.wait()
login = selenium.find_elements_by_name('loginfmt')[0]
login.send_keys(user)
next_step = selenium.find_element_by_id('idSIButton9')
next_step.click()
time.sleep(1)
password = WebDriverWait(selenium, 10).until(
# EC.presence_of_element_located((By.NAME, "passwd"))
EC.element_to_be_clickable((By.ID, "i0118"))
)
**password.send_keys(psw)**
# password.submit()
next_step = selenium.find_element_by_id('idSIButton9')
next_step.click()