Reputation: 65
in short I am getting an exception after the code that gives the exception suceeds.
def checkelementid(id1):
try:
second_driver.find_element_by_id(id1).click()
except NoSuchElementException:
return False
except ElementNotInteractableException:
return False
return True
if checkelementid("requisitionDescriptionInterface.UP_APPLY_ON_REQ.row1"):
print("before")
second_driver.find_element_by_id("requisitionDescriptionInterface.UP_APPLY_ON_REQ.row1").click()
print("after")
I get the following error after the click succeeds and I go to a new url:
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: [id="requisitionDescriptionInterface.UP_APPLY_ON_REQ.row1"]
So it actually finds the element and clicks and get taken to a new site but it somehow runs the click again on the new site but obviously cant find the element. It prints "before" but does not print "after".
Upvotes: 1
Views: 58
Reputation: 1166
Try to put wait before if condition.
wait = WebDriverWait(driver, 10)
element = wait.until(EC.element_to_be_clickable((By.ID, 'someid')))
Upvotes: 1