Please help in performing mouseover action on an element in Selenium.
1 Like
You can use the Actions class for performing mouseover action in Selenium, with the help of moveToElement() method, as shown in the code below.
Example
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
import java.util.concurrent.TimeUnit;
public class MouseOver{
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\lambdatestPC\\Desktop\\Java\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String url = "https://www.lambdatest.com";
driver.get(url);
driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
// Instantiating Actions class in Selenium
Actions a = new Actions(driver);
// Performing mouseover action using moveToElement() method
a.moveToElement(driver.findElement(By.xpath(“input[@type=’text’]))).
build().perform();
driver.quit();
}
}
1 Like