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:
- Message: Element could not be scrolled into view while trying to click on an option within a dropdown menu through Selenium
- org.openqa.selenium.ElementNotInteractableException: Element could not be scrolled into view when trying to click a button
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:
- move_to_element() from selenium.webdriver.common.action_chains
- element_to_be_clickable() from selenium.webdriver.support.expected_conditions
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()
This usecase
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: