How To Click On Windows Menu Which Populate On Mouse Hover Using Selenium
A JavaScript function which load menu at run time. On mouse hover over, the LoadMenu function loads the menu item and I need the location assosciated with it on MouseClick() event.
Solution 1:
Have you ever tried the Action
interface?
Especially the point "Generating Action chains" should help you
I do it like that:
privatevoidhoverAndClick(WebElement[] hoverer, WebElement element){
Actionsactions=newActions(this.driver);
for (WebElement we : hoverer) {
Actionhovering= actions.moveToElement(we).build();
hovering.perform();
}
element.click();
}
If you only need one element to hover for ever, remove the array and the ateration or copy this:
privatevoidhoverAndClick(WebElement hover, WebElement element){
Actionsactions=newActions(this.driver);
Actionhovering= actions.moveToElement(hover).build();
hovering.perform();
element.click();
}
Solution 2:
I would modify case 5 you described:
// case 5 tried by executing javascript and search element by id
element = driver.findElement(By.id("menuItem4"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("$('div#menuItem4.menuItem').hover();");
element.click();
in the following way;
String cssSelector="[id='menuItem4']";
publicvoidjsClick(String css){
JavascriptExecutor js = (JavascriptExecutor) driver;
StringBuilder stringBuilder = newStringBuilder();
stringBuilder.append("var x = $(\'"+css+"\');");
stringBuilder.append("x.click();");
js.executeScript(stringBuilder.toString());
}
jsClick(cssSelector);
hope this somehow helps you)
Post a Comment for "How To Click On Windows Menu Which Populate On Mouse Hover Using Selenium"