To perform a 'mouse
hover' action in selenium web driver API, we define to chain all of the actions
that we want to find in one go so move
to the element that which already has sub elements and click on the child item.
It is the same way that we are doing normally to click on a sub menu item.
With the help of actions
object you should move the menu title, and then move to the sub menu item and
click on it.
Below is the sample automation
script to perform Mouse hover action
ie 1:
Actions actions = new Actions(driver);
WebElement mainMenu =
driver.findElement(By.linkText("menulink"));
actions.moveToElement(mainMenu);
WebElement subMenu =
driver.findElement(By.cssSelector("subLinklocator"));
actions.moveToElement(subMenu);
actions.click().build().perform();
ie 2:
Actions action = new Actions(webdriver);
WebElement mainMenutest =
webdriver.findElement(By.linkText("MainMenu"));
action.moveToElement(mainMenutest).moveToElement(webdriver.findElement(By.xpath("submenuxpath"))).click().build().perform();
There are such a cases
where you may just want to mouse hover on particular element and check if the
button state or color is changing after mouse hover.
Check below is the good example
WebElement searchButton =
driver.findElement(By.id("searchbtn"));
Actions action = new Actions(driver);
action.moveToElement(searchButton).perform();
No comments:
Post a Comment