move_to_element
kongdd opened this issue · comments
RSelenium has no function move_to_element
https://www.geeksforgeeks.org/move_to_element-method-action-chains-in-selenium-python/
Hi there, you can use the mouseMoveToLocation() method for that. This function takes 3 arguments:
- x: offset value of x coordinate
- y: offset value of y coordinate
- webElement: the element you would like to move the mouse to
To move the mouse to the center of the element, just provide the webElement parameter. Leave the offset values empty. Here is an example
library(RSelenium)
remDr <- rsDriver(browser = 'chrome',
chromever = '97.0.4692.71')
# to check your chrome version, open Chrome and in the URL box type
# chrome://version
# your version type will be at the top of the page
# then go to R, and in the console type:
# binman::list_versions('chromedriver')
# it will give you a list of versions, pick the one that has the same first 2 digits as yours
# access the client
remDr <- remDr$client
# open a new session and navigate to wikipedia
remDr$open()
remDr$navigate('https://www.wikipedia.org')
# Find the element with text English
english <- remDr$findElement(using = 'xpath', '//a[@title="English — Wikipedia — The Free Encyclopedia"]')
# use this function to move the cursor to the center of the element
# only provide the webElement parameter if you want the cursor to move to the middle of the element
remDr$mouseMoveToLocation(webElement = english)
# The element should be highlighted. You can test it by clicking on it
remDr$click()
Let me know if this helps!
Thanks very much for your solution. That is just what I need.