Here is the very basic program to get text from web element which is displayed on mouse over using Actions. In the below example I going to get text from the homepage of Hello Selenium which comes when performing mouse over on author name.
Java Source code:
package com.helloselenium.selenium.test; 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 getMouseOverText{ public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.navigate().to("http://helloselenium.blogspot.com"); WebElement link = driver.findElement(By.xpath("//a[@rel='author']")); new Actions(driver).moveToElement(link).build().perform(); String linkTitle = link.getAttribute("title"); System.out.println(linkTitle); } }
Detailed explanation for the above program is as follows:
Following code is the required packages for Selenium.
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;
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://helloselenium.blogspot.com");
driver.navigate().to("http://helloselenium.blogspot.com");
WebElement link = driver.findElement(By.xpath("//a[@rel='author']"));
new Actions(driver).moveToElement(link).build().perform();
String linkTitle = link.getAttribute("title");
System.out.println(linkTitle);
0 Comments
What would you like to add in my list? I look forward to reading your comments below.