Issue
The code in this post only seems to open up the browser and do nothing else. I would like to use the move_to_location
action. Currently I am just trying to see if it works so I am attempting to open a website that allows you to paint, going to a random spot and clicking to create a dot.
Why is the code below not doing what I described above? It just opens the browser at the link provided.
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://kleki.com/")
action = webdriver.common.action_chains.ActionChains(driver)
action.pointer_action.move_to_location(50, 50).perform()
action.click().perform()
Solution
I run your code and I got the following error:
Traceback (most recent call last):
File "C:\Users\0.py", line 6, in <module>
action.pointer_action.move_to_location(50, 50).perform()
^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'ActionChains' object has no attribute 'pointer_action'
The ActionChains class in Selenium does not have a direct method named pointer_action
.You should use the move_by_offset
method from the ActionChains class.
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from time import sleep
driver = webdriver.Chrome()
driver.get("https://kleki.com/")
# wait for the page to load
driver.implicitly_wait(10)
# 1 second wait
sleep(1)
action = ActionChains(driver)
# move to a position relative to the current mouse position and click
action.move_by_offset(100, 150).click().perform()
# sleep to see if the mouse clicked
sleep(5)
Note: you need to calculate the current position of the mouse and then provide the offset accordingly.
Answered By - Obaskly
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.