1

Using selenium with java I want to vary whether an image is zoomed when the cursor is moved over the image. From the source code below, element changes:

Before zoom: <div class="powatag-zoom powatag-hidden">

After zoom: <div class="powatag-zoom">

Any help to assert the change with working code is welcome.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195

1 Answers1

2

One possible approach would be to check the value of getAttribute("class") before and after the mouse move action:

WebElement we = webdriver.findElement(By.cssSelector("div.powatag-zoom"));
assertEquals(we.getAttribute("class"), "powatag-zoom powatag-hidden");

Actions action = new Actions(webdriver);
action.moveToElement(we).build().perform(); 

assertEquals(we.getAttribute("class"), "powatag-zoom");

You can also check the size of the element using getSize.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Thanks It worked ... but i was hoping if you can help me write a function for the above code .. that will be gr8.. as i dont have to put so many lines of code everytime i want to use it . – user3616172 May 07 '15 at 10:27
  • @user3616172 it is a good idea to make this code reusable if you are going to use it more than once. I'll refer you to a useful thread: http://stackoverflow.com/questions/4939601/how-can-i-add-code-reuse-to-my-selenium-tests, should help. – alecxe May 07 '15 at 11:03