I have ran into a problem while trying to run the following script:
def searchByBrand(brand):
try:
driver.implicitly_wait(20)
action = ActionChains(driver)
cat_button = driver.find_element_by_xpath(
"//button[@class='icon-btn icon-btn--no-text icon-btn--primary']"
)
driver.implicitly_wait(10)
CHECKBOX_XPATH = "//input[@type='checkbox' and @aria-label='Acer']"
checkbox = driver.find_element_by_xpath(CHECKBOX_XPATH)
# Clicks the "Filter by" button
action.move_to_element(cat_button).click().perform()
# Waits until checkbox is present, then waits until it's visible
# and then clicks it
wait = WebDriverWait(driver, 20).until(
EC.visibility_of_element_located((By.XPATH,CHECKBOX_XPATH)))
driver.execute_script("document.body.style.transform='scale(0.5)';")
time.sleep(3)
driver.execute_script("arguments[0].scrollIntoView();", wait)
time.sleep(3)
wait = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH,CHECKBOX_XPATH)))
action.move_to_element(wait).click().perform()
finally:
print("Filtered successfully.")
This is the output after running it:
o@o-pc:~$ python selenium_example.py
Filtered successfully.
Traceback (most recent call last):
File "selenium_example.py", line 86, in <module>
main()
File "selenium_example.py", line 82, in main
searchByBrand("Acer")
File "selenium_example.py", line 77, in searchByBrand
action.move_to_element(wait).click().perform()
File "/home/o/.pyenv/versions/3.8.3/lib/python3.8/site-packages/selenium/webdriver/common/action_chains.py", line 80, in perform
self.w3c_actions.perform()
File "/home/o/.pyenv/versions/3.8.3/lib/python3.8/site-packages/selenium/webdriver/common/actions/action_builder.py", line 76, in perform
self.driver.execute(Command.W3C_ACTIONS, enc)
File "/home/o/.pyenv/versions/3.8.3/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/o/.pyenv/versions/3.8.3/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.MoveTargetOutOfBoundsException: Message: (304, -148) is out of bounds of viewport width (681) and height (669)
I tried the solutions proposed in this question: Selenium - MoveTargetOutOfBoundsException with Firefox
I didn't quite get the "accepted" answer. I also tried zooming out and putting sleeps in between actions/scripts; didn't work. Haven't tried rezising the Firefox window since I'm using a tiling windows manager (I don't know if that affects the performance of my script).
EDIT: I tried the same script not using i3 (the tiling windows manager I mentioned), commented
action.move_to_element(cat_button).click().perform()
And it worked. Any thoughts?