I am working on automating the IdentiGO application for my company, and I'm getting the following error:
Internal Server Error: /identigo Traceback (most recent call last): File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response response = self.process_exception_by_middleware(e, request) File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/django/views/generic/base.py", line 71, in view return self.dispatch(request, *args, **kwargs) File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/django/views/generic/base.py", line 97, in dispatch return handler(request, *args, **kwargs) File "/Users/jane/Code/maynard_env/maynard/employee/views.py", line 63, in post driver.main(employee) File "/Users/jane/Code/maynard_env/maynard/employee/driver.py", line 31, in main WebDriverWait(driver, 1000000).until(EC.presence_of_element_located((By.XPATH, '/html/body/div[5]/div[3]/div/button/span'))).click() File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py", line 80, in click self._execute(Command.CLICK_ELEMENT) File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute return self._parent.execute(command, params) File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response) File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementNotInteractableException: Message: Element <span class="ui-button-text"> could not be scrolled into view
Here is my code, with the scripts leading up to this page omitted since they aren't relevant to my problem.
from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC WebDriverWait(driver, 1000000).until(EC.presence_of_element_located((By.XPATH, '/html/body/div[5]/div[3]/div/button/span'))).click()
On the page prior to this code, where the user selects an appointment date and time; I want the script to wait for the "Go" button to be pushed, then click on "Continue" in the following screenshot:
If you would like to see the exact page, go to this url, then you will have to make a series of POST requests using the following info:
Any advice would really be appreciated!
Here is a JS Fiddle with the html of the page:
https://jsfiddle.net/khf4tym3/
When I click "view page source", the popup html doesn't show in the source code, so I assume that it is generated with JS.
<div class="ui-dialog-buttonset"> <button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false"> <span class="ui-button-text">Continue</span> </button> </div>
If I change the line WebDriverWait(driver, 1000000)
to WebDriverWait(driver, 30)
, I get the following error instead:
Internal Server Error: /identigo Traceback (most recent call last): File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response response = self.process_exception_by_middleware(e, request) File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/django/views/generic/base.py", line 71, in view return self.dispatch(request, *args, **kwargs) File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/django/views/generic/base.py", line 97, in dispatch return handler(request, *args, **kwargs) File "/Users/jane/Code/maynard_env/maynard/employee/views.py", line 63, in post driver.main(employee) File "/Users/jane/Code/maynard_env/maynard/employee/driver.py", line 34, in main element=WebDriverWait(driver,30).until(EC.element_to_be_clickable((By.XPATH,"//div[@class='ui-dialog-buttonset']/button[@class='ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only']/span[contains(.,'Continue')]"))) File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/selenium/webdriver/support/wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
code for the project so far, so you can skip the forum entry.
https://jsfiddle.net/93k5s2xg/1/
The working solution:
WebDriverWait(driver, 20).until(expected_conditions.element_to_be_clickable((By.XPATH, "//div[starts-with(@aria-describedby, 'ui-id-')]//span[@class='ui-button-text' and text()='Continue']"))).click()
This error message...
selenium.common.exceptions.ElementNotInteractableException: Message: Element <span class="ui-button-text"> could not be scrolled into view
...implies that the WebDriver instance i.e. driver was unable to scroll the element within the Viewport to invoke click()
.
First of all, as your usecase is to invoke click()
on the element, ideally instead of using presence_of_element_located()
you need to use the ExpectedConditions as element_to_be_clickable()
as follows:
WebDriverWait(driver, 1000000).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[5]/div[3]/div/button/span'))).click()
You can find a couple of detailed discussions in:
As an alternative, as per the error message, to scroll an element within the Viewport before invoking click()
you can also use the Element.scrollIntoView() method.
You can find a detailed discussion in: - What is the difference between the different scroll options?
At this point it is worth to mention, the following methods:
will automatically scroll the element within the Viewport.
You can find a detailed discussion in: - How to scroll a webpage using selenium webdriver in Python without using javascript method execute_script()
The button with text as Continue is within the Top Level Content but rendered within a Modal Dialog Box.
DevTools Snapshot:
As the desired element is within a Modal Dialog Box, so to locate and invoke click()
on the element you have to induce WebDriverWait for the element_to_be_clickable()
and you can use the following Locator Strategy:
Using XPATH
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[starts-with(@aria-describedby, 'ui-id-')]//span[@class='ui-button-text' and text()='Continue']"))).click()
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
DevTools Snapshot:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With