2

I need to test the change in background color to #F67621 on hovering. The background color code is to be compared with predefined expected value. I am using XPath as selector.

String xPathStr="//input[@id='add']";
String str = driver.findElement(By.xpath(xPathStr)).getCssValue("background-color");

For above code can somebody suggest me how to check for hovering of button
CSS for the above mentioned code is as follows:

# add:hover , #clear:hover{
    background-color:#F67621;
}
Suhird Singh
  • 121
  • 2
  • 14

2 Answers2

2

I'm not sure, but i find this :

How to perform mouseover function in Selenium WebDriver using Java?

Actions action = new Actions(driver);
WebElement we = driver.findElement(By.id("Add"));
action.moveToElement(we).perform();
assertEquals("#F67621", we.getCssValue("background-color"));

Other link :

http://www.learnseleniumtesting.com/mouse-hover-and-other-mouse-events-in-webdriver/

Community
  • 1
  • 1
1
WebElement mousehover=org.findElement(By.xpath("html/body/div[1]/div/div[1]/div/div/div[2]/div[1]/ul/li[3]/a"));
Actions action = new Actions(org);
action.moveToElement(mousehover).build().perform();
Ghasem
  • 14,455
  • 21
  • 138
  • 171
Amit Pal
  • 177
  • 3
  • 11