Issue
To click on a specific location on the screen I use the following code:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.action_chains import ActionChains
import time
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.set_window_size(500, 500)
driver.get('https://clickclickclick.click/')
actions = ActionChains(driver)
x_coord, y_coord = 250, 182 #coordinates of the button
actions.move_to_location(x_coord, y_coord).click().perform()
This piece of code clicks the prominently placed button on the website without raising an error if the code is ran on a Windows 10/11. If the code is ran on Linux Mint the following error occurs:
AttributeError: 'ActionChains' object has no attribute 'move_to_location'
I did not succeed in finding the function in the documentation of selenium. Does anybody now if there is a way to make move_to_location
also work on Linux Mint? Thank you for your time and effort in advance!
Edit: to illustrate this further print(hasattr(actions, 'move_to_location'))
returns True
on Windows 10/11 and False
on Linux Mint
Solution
ActionsChains
class does not have a method called move_to_location
.
However, ActionsBuilder
class has this method. See the below code:
actions = ActionBuilder(driver)
actions.pointer_action.move_to_location(<x_coord>, <y_coord>).click()
actions.perform()
Update: Check the official documentation from below link for ActionChains
, you will not find that method. I suggest recheck your code again to ensure move_to_location
is being accessed by which class. It has to be ActionBuilder
https://www.selenium.dev/selenium/docs/api/py/webdriver/selenium.webdriver.common.action_chains.html
Answered By - Shawn Answer Checked By - Marilyn (WPSolving Volunteer)