1

I'm using FluentLenium.

I'm trying to simulate a on_mouse_over in my java tests. I have to check some boxes in a drop down menu, it's an element not visible...

I have to move the mouse over to make visible this element and be able to use the method click() from FluentLenium.

How can i "simulate" a on_mouse_over in java?

Thanks

JBL
  • 12,588
  • 4
  • 53
  • 84
Hackilltour
  • 113
  • 1
  • 9

2 Answers2

3

Thanks everyone for your help !

I found the solution :

Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.cssSelector("ul.critereFiltrage")).findElement(By.cssSelector("a"))).moveToElement(driver.findElement(By.cssSelector("div.overview")).findElement(By.cssSelector("a"))).click().build().perform();

To explain :

  • The first moveToElement() => To go on the A-tag to open the DropDown menu
  • The second moveToElement() => To go on the first item in the DropDown Menu
  • click() => click on the selected item
  • build() => To generate a composite action
  • perform() => To launch the built action.

Thanks a lot,

Hackilltour
  • 113
  • 1
  • 9
1

You would need to use the Actions() class.

Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.id("opens_menu"))).moveToElement(driver.findElement(By.id("hidden_element"))).click().build().perform();

Docs are here: http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/interactions/Actions.html

Mark Rowlands
  • 5,357
  • 2
  • 29
  • 41
  • Actually I just noticed you're using Fluentlenium, rather that WebDriver. As such I can't guarantee that you have access to the `Actions()` class. If not, please let me know and I'll delete my answer so avoid confusion in the future. – Mark Rowlands Jun 20 '13 at 14:47
  • I tried something like you : action.moveToElement((WebElement) ((Actions) driver.findElement(By.id("div.zoneFiltrage"))).moveToElement(find("div.zoneFiltrage").find("ul.critereFiltrage").findFirst("div.overview").findFirst("li").findFirst("a").getElement())).click().build().perform(); I think that my major problem is : I don't have ID for that dropDownMenu ... When i try to create my test with Selenium IDE 2.0 and export it in JAVA JUNIT4 / WebDriver. I can't run and succeed that test because Selenium IDE probably By-Pass the move_over. – Hackilltour Jun 20 '13 at 15:58
  • `driver.findElement(By.id("div.zoneFiltrage")` That looks more like a css selector - have you tried `driver.findElement(By.css("div.zoneFiltrage"))`? – Mark Rowlands Jun 20 '13 at 16:12