In order to perform a 'mouse hover' action, we need to chain all of the actions that we want to achieve in one go. So move to the element that which has sub elements and click on the child item. It should the same way what we do normally to click on a sub menu item.
With the actions object you should first move the menu title, and then move to the sub menu item and click it.
Below is the sample code to perform Mouse hover action
Practice Yourself:
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();
Practice Yourself:
Actions action = new Actions(webdriver);
WebElement mainMenu = webdriver.findElement(By.linkText("MainMenu"));
action.moveToElement(mainMenu).moveToElement(webdriver.findElement(By.xpath("submenuxpath"))).click().build().perform();
There are cases where you may just want to mouse hover on particular element and check if the button state/color is changing after mouse hover.
WebElement searchBtn = driver.findElement(By.id("searchbtn"));
Actions action = new Actions(driver);
action.moveToElement(searchBtn).perform();
I really enjoy the blog.Much thanks again. Really Great selenium online course
ReplyDeleteGreat One..It was informative..i suggest this blog to my friends..keep update best selenium training institute in chennai
ReplyDeleteTraining with placement in chennai
Top selenium training institutes in chennai
en son çıkan perde modelleri
ReplyDeletelisans satın al
en son çıkan perde modelleri
uc satın al
nft nasıl alınır
özel ambulans
yurtdışı kargo
minecraft premium