I try to trigger hover event over an element declared by xpath statement in selenium webdriver:
((JavascriptExecutor) driver).executeScript("$('(//span[@class='attribute-square-container'])[2]').hover();");
but I'm receiving:
org.openqa.selenium.JavascriptException: SyntaxError: missing ) after argument list
What is incorrect in above line?
I changed code a litle bit:
String script = "$(`#image-squares-8 > li:nth-child(2) > label > span > span`).hover();";
((JavascriptExecutor) driver).executeScript(script);
It now executes without exception but it do nothing, namely tooltip window do not appear over small image.
Is it something wrong with this code?
I tried code from @JeffC but it does not work on page demo.nopcommerce.com/nike-floral-roshe-customized-running-shoes
I would like to trigger mouseover event to show tooltip over "print" images but it does not work in javascript and firefox (with chrome it works). With firefox I received:
org.openqa.selenium.interactions.MoveTargetOutOfBoundsException: Move target (807, 750) is out of bounds of viewport dimensions (1536, 731)
Solution
Such code works with Firefox also:
public void moveToElemenent(WebElement element) {
Capabilities cap = ((RemoteWebDriver) driver).getCapabilities();
if(cap.getBrowserName().startsWith("firefox")) {
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
}
Actions action = new Actions(driver);
action.moveToElement(element).perform();
}