Mousehover action in selenium WebDriver –
In the Actions class, the user, can perform one action, by simply calling it into the driver instance, followed by the method perform().
Let us see about mousehover action in selenium. If the menu bar or anywhere on the page, the menu has dropdown, and the dropdown options appear only when you hover the mouse on that menu.
Let us see, hot this can be achieved.
In my blog (URL: http://automationtalks.com/), suppose you want to select the sub-menu (Selenium WebDriver) of Menu: Selenium.
- Open the browser.
- Mouse Hover on “Selenium Tutorial” tab present in the top navigational bar.
- Select the Menu which you want to click on (let us consider here as – “Selenium WebDriver”.
- Click on the “Selenium WebDriver”.
- Close the browser.
Actions act = new Actions(driver);
Then, mousehover using actions class, syntax below –
act.moveToElement(driver.findElement(“webelement_Menu_location”)).build().perform();
Now, the submenu should be visible, Then click on the submenu –
driver.findElement(“WebElement_submenu”).click();
Below is the example how can be mouse hover achieved in selenium WebDriver.
package demoPackage1; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Actions; import org.testng.annotations.Test; public class ActionsClass { @Test public void TestCase() throws InterruptedException{ System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.navigate().to("http://automationtalks.com/"); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); Actions act = new Actions(driver); //Define actions class & move to webelement (Hove mouse to webelement) act.moveToElement(driver.findElement(By.xpath("//span[contains(.,'Selenium Tutorial')]"))).build().perform(); //After mouse hover, element form dropdown is appeared, then click on it. driver.findElement(By.xpath("//a[contains(.,'Selenium WebDriver')]")).click(); Thread.sleep(3000); driver.close(); driver.quit(); } }
To learn more about Actions Class –
Actions class in Selenium WebDrivr
MouseHover action in selenium WebDriver
Right Click (Context click) in Selenium
Verify Tool Tip Message text using Selenium WebDriver
How to Perform series of actions using Actions class in selenium WebDriver?
How to use tab button in selenium WebDriver?
How to perform Drag and Drop operation using selenium WebDriver?
How to send text in capital letters into a text-box using Actions class in Selenium WebDriver?
How to refresh webpage using Action class in selenium WebDriver?
Upload file in Selenium Using ROBOT Class
Upload file in Selenium using sendKeys() method
Hope This Helps !!!!
abc
Prakash Narkhede
abc
Prakash Narkhede