Hi companions! in this post, we will figure out how to computerize the mouseover over a component utilizing Selenium Webdriver with Java. For playing out the mouse float over a component in Selenium, we utilize the Actions class. The Actions class gave by Selenium Webdriver is utilized to produce complex client motions including mouseover, right-click, double tap, drag, and drop, and so forth.
Code scrap to mouseover
Actions action = new Actions(driver);
WebElement element = driver.findElement(By.id("elementId"));
action.moveToElement(element).perform();
Here, we are starting up an object of Actions class. From that point onward, we pass the WebElement to be mouse drifted as a parameter to the moveToElement() strategy present in the Actions class. At that point, we will call the perform() technique to play out the created activity.
Test code to mouse float over a component
For the show of the mouseover activity, we will dispatch a Sample Site for Selenium Learning. At that point we will mouse drift over the 'Submit' button. This will bring about a tooltip age, affirming that the mouseover activity is effectively performed.
package seleniumTutorials;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class MouseOver {
public static void main(String[] args) throws InterruptedException{
WebDriver driver = new FirefoxDriver();
//Launching sample website
driver.get("https://artoftesting.com/samplesiteforselenium");
driver.manage().window().maximize();
//Mouseover on submit button
Actions action = new Actions(driver);
WebElement btn = driver.findElement(By.id("idOfButton"));
action.moveToElement(btn).perform();
//Thread.sleep just for user to notice the event
Thread.sleep(3000);
//Closing the driver instance
driver.quit();
}
}