Most of the main code
driver.get(url)
usernameelem = driver.find_element(By.XPATH,usernameId)
usernameelem.send_keys(username)
passwordelem = driver.find_element(By.XPATH,passwordId)
passwordelem.send_keys(password)
passwordelem.send_keys(Keys.ENTER)
try:
submitbut = driver.find_element(By.XPATH,submit_buttonId)
submitbut.click()
except:
submitbut1 = driver.find_element(By.XPATH,submit_buttonId)
submitbut1.send_keys(Keys.ENTER)
time.sleep(5)
The code am not so sure about:
try:
submit = driver.find_element(By.XPATH,submit_buttonId)
submit.click()
except:
submit = driver.find_element(By.XPATH,submit_buttonId)
submit.send_keys(Keys.ENTER)
This is the only block of code that works, when i try to make it click on the submit button
Any other method such as
submit = driver.find_element(By.XPATH,submit_buttonId)
submit = driver.find_element(By.XPATH,submit_buttonId)
submit.send_keys(Keys.ENTER)
trying to anticipate the error.. or
try:
submit = driver.find_element(By.XPATH,submit_buttonId)
submit.click()
except:
submit = driver.find_element(By.XPATH,submit_buttonId)
submit.click()
literally the same thing but clicking
Doesn't work and will always gives "selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: stale element not found"
Am not sure how and why its only workable in such a specific order, the submit button is always visible too, and clickable if manual
Without seeing the page it's hard to know for sure but it sounds like the page is loaded and then at least a portion of the page is reloaded. This creates the StaleElementException. The stale element is in
submit... you've grabbed the element reference from the page and stuffed it intosubmit. The page then reloads so thatsubmitis no longer pointing at anything (it's reference is stale). The only fix for this is to get the reference again... that's why you're having to call the same line twice, the first time inside atry.The way to avoid this is to
It sounds like a lot of work but this procedure should remove a lot of the intermittent (and deterministic) failures in these steps. The code would look like