ropensci / RSelenium

An R client for Selenium Remote WebDriver
https://docs.ropensci.org/RSelenium
343 stars 81 forks source link

move_to_element #254

Closed kongdd closed 2 years ago

kongdd commented 2 years ago

RSelenium has no function move_to_element https://www.geeksforgeeks.org/move_to_element-method-action-chains-in-selenium-python/

ggSamoora commented 2 years ago

Hi there, you can use the mouseMoveToLocation() method for that. This function takes 3 arguments:

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!

kongdd commented 2 years ago

Thanks very much for your solution. That is just what I need.