RSelenium icon indicating copy to clipboard operation
RSelenium copied to clipboard

simulate mouseover/mouseout events?

Open tdhock opened this issue 9 years ago • 3 comments

Any ideas how I could write a test for functionality that I have implemented in a JavaScript function that is called on mouseover/mouseout events?

I found the mouseMoveToLocation function but it does not seem to generate a call to my handler function.

I also tried using executeScript but that generated an error

> remDr$executeScript('return document.getElementById("chrM").onmouseover();')
Error:   Summary: UnknownError
     Detail: An unknown server-side error occurred while processing the command.
     class: ReqHand
> 

tdhock avatar Oct 26 '15 16:10 tdhock

here is a minimal reproducible example

library(RSelenium)
startServer()
remDr <- remoteDriver(browserName="firefox")
remDr$open()

bug.html <- file.path(tempdir(), "RSelenium-bug.html")
cat('<!DOCTYPE html>
<html>
<body>

<h1 id="head"
onmouseover="',
    "this.style.color = 'red'",
    '" onmouseout="',
    "this.style.color = 'black'",
    '">My First Heading</h1>

<p>My first paragraph.</p>

</body>
</html>', file=bug.html)

remDr$navigate(paste0("file://", bug.html))

e <- remDr$findElement("id", "head")
remDr$mouseMoveToLocation(webElement=e)

output is

> remDr$mouseMoveToLocation(webElement=e)
Error:   Summary: InvalidElementState
     Detail: An element command could not be completed because the element is in an invalid state (e.g. attempting to click a disabled element).
     class: org.openqa.selenium.InvalidElementStateException

tdhock avatar Oct 26 '15 16:10 tdhock

Hi Toby,

Are you running this on a MAC? This is likely an issue with native events and Selenium. Depending on the version of firefox/Selenium native events may not function. You can check what versions of selenium server have support for native events for versions of firefox by referencing the changelog. For example https://github.com/SeleniumHQ/selenium/blob/master/java/CHANGELOG The MRE works for example if I run it on windows with firefox 41.0.2 and selenium server 2.48.0

johndharrison avatar Oct 26 '15 17:10 johndharrison

running this on Ubuntu with

thocking@silene:~/R/animint(PredictedPeaks)$ firefox --version
Mozilla Firefox 11.0
thocking@silene:~/R/animint(PredictedPeaks*)$ phantomjs --version
1.9.8
thocking@silene:~/R/animint(PredictedPeaks*)$ 

so I guess upgrading is the solution.

but also we would like to test such "native events" in phantomjs too. Is that possible? Doesn't work with the version I have.

tdhock avatar Oct 27 '15 20:10 tdhock