In the article we are going to discuss how to retrieve TEXT from Mouse Hover on the Webelelment.
In this Program :
- Navigating to https://www.facebook.com/
- Mouse hover on facebook icon
- Retrieve the text "Go to Facebook home" from below webelement'
<a title="Go to Facebook Home" href="/">
- To Achieve this we need to identify the webelements using xpath.
WebElement element1=driver.findElement(By.xpath(".//[@id='blueBarNAXAnchor']/div/div/div/div[1]/h1/
a"));
We were going to use Actions Class to perform mouse operation
Actions ac= new Actions(driver);
ac.moveToElement(element1).build().perform();
Source code :
import
java.util.concurrent.TimeUnit;
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 mousehover{
public static void main(String args[]) throws InterruptedException
{
WebDriver
driver;
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10,
TimeUnit.SECONDS);
driver.get("http://www.facebook.com");
Thread.sleep(7000);
WebElement element1=driver.findElement(By.xpath(".//*[@id='blueBarNAXAnchor']/div/div/div/div[1]/h1/a"));
Actions ac= new Actions(driver);
ac.moveToElement(element1).build().perform();
String hovertext=element1.getAttribute("title");
System.out.println(hovertext);
}
}
Run the above program
Output
Hope u Like this Post.
Add comments.
No comments:
Post a Comment