0
votes

I'm running a Python script that uses Selenium + Chromedriver to automate a series of actions on a web app. Several of these actions causes the page or frame to reload. Since Selenium does not have a built-in "wait for page load" feature and I would rather not use time.sleep(x) if I can avoid it, I have used this combo frequently:

wait = WebDriverWait(driver, 10)
driver.find_element_by_id("sysverb_update_and_stay").click() #causes form to submit and data to load
element = wait.until(EC.presence_of_element_located((By.ID, "view.change_task.parent")))
element = wait.until(EC.element_to_be_clickable((By.ID, "view.change_task.parent")))

Based on the documentation I have read (and the name of the attribute itself), I expected that the script would wait until an element with that ID was present before continuing, and that if it did not find the element within the script's built-in timeout, only then would the script crash out and throw an exception. However, as soon as the script hits the the first wait line, it crashes and throws the following exception:

Traceback (most recent call last): File "servicenow.py", line 137, in test_change_control element = wait.until(EC.presence_of_element_located((By.ID, "view.change_task.parent") )) ... selenium.common.exceptions.WebDriverException: Message: unknown error: unhandled inspec tor error: {"code":-32000,"message":"Cannot find context with specified id"}

If it can't find that element by the ID, isn't it supposed to, you know, wait for it to be present? What am I missing here?

EDIT: Added wait in code above, and HTML for element below:

<a id="view.change_task.parent" name="view.change_task.parent" style="" class="btn btn-default btn-ref icon icon-info" data-type="reference_popup" data-table="change_task" data-form="task.do" data-ref="change_task.parent" data-ref-key="null" data-view="" tabindex="-1"><span class="sr-only">View - Opens reference record in current window</span></a>
1
Share what is the wait along with the HTML for element with id="view.change_task.parent"Andersson
@Andersson Updated original postipenguin67
Did you check this answer?Andersson
I hadn't seen that one -- looks like updating the chromedriver to the latest version cleared the issue. Thanks!ipenguin67

1 Answers

0
votes

This appears to be an issue with earlier versions of Chromedriver -- updating to the latest version appears to have solved this.