简体   繁体   中英

In selenium can I perform getCSSValue("color") after mouse hover action

There is a scenario where I hover on element and then one vertical line starts showing and I want to getCSSValue of that element after hover.

Normally without hovering directly by using xpath.getCSSValue("color"); is giving me color but what I want is first hover on that element then it will start showing the red color vertical line and then to take color value.

I know/tried, getCSSValue("color") on action class method, but action class is not allowing it.

public By hoverOnAccount = By.xpath("myxpath"); 
WebElement abcd = driver.findElement(hoverOnAccount);
String abc = abcd.getCssValue("color");

Can anyone suggest?

This should work, please also add the actions method you tried.

WebElement hoverElement = driver.findElement(yourElementSelector);
Actions action = new Actions(driver);
action.moveToElement(hoverElement).build().perform();

hoverElement.getCSSValue("color");

If that one won't work you can try that action with JavaScript Executor :

String javaScript = "var evObj = document.createEvent('MouseEvents');" +
                    "evObj.initMouseEvent(\"mouseover\",true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);" +
                    "arguments[0].dispatchEvent(evObj);";


((JavascriptExecutor)driver).executeScript(javaScript, hoverElement);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM