Using selenium webdriver, How to capture tooltip ?
Capturing tool-tip of element using web-driver script in java. Tooltip is displayed in on the page only when user hover the mouse over it. Only then the related attributes can be identified in dev toolbar of browser. if we search for the title of toolbar then it cannot be located using dev-toolbar.
When user mouse hover on the text field, it will display the tool tip. But when you observer the HTML, it doesn't have any title attribute. When ever user mouse hover, it will generate a div tag in which tool tip text resides.
Steps to be automated are:
1. Open url of the webapp.
2. Switch to Frame
3. Identify the element
4. Mouse Hover on the text field using Actions class
5. Get tool tip text by attribute :]]]]]]-------->>>> (for this step to get the tooltip user need to hover the mouse over the element, then div attribute is displayed (can be seen using dev toolbar) and using this attribute we can capture the tool tip.
2. Switch to Frame
3. Identify the element
4. Mouse Hover on the text field using Actions class
5. Get tool tip text by attribute :]]]]]]-------->>>> (for this step to get the tooltip user need to hover the mouse over the element, then div attribute is displayed (can be seen using dev toolbar) and using this attribute we can capture the tool tip.
Following line of java code ( with TESTNG) shows how it works using seleniun webdriver and its action class.
package Madhus.Example;
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;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class Capturing_ToolTip {
String seleniumURL = "http://docs.seleniumhq.org";
String jQueryURL = "https://jqueryui.com/tooltip/";
public WebDriver driver;
@BeforeClass
public void setUp() {
driver = new FirefoxDriver();
driver.manage().window().maximize();
}
@Test
public void toolTipCase2() {
driver.navigate().to(jQueryURL);
// As there is frame, we have to navigate to frame
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector(".some-frame")));
// Text box field, where we mouse hover
WebElement element = driver.findElement(By.id("id_name"));
// Below steps will move the mouse on the required element and then get the attribute of
// element which appears after hovering the mouse.
// Use action class to mouse hover on Text box field
Actions action = new Actions(driver);
action.moveToElement(element).build().perform();
WebElement toolTipElement = driver.findElement(By.cssSelector(".Attributename"));
// To get the tool tip text and assert
String toolTipText = toolTipElement.getText();
Assert.assertEquals("This is the tooltip which will be located by this script.", toolTipText);
}
@AfterClass
public void tearDown() {
if (driver != null) {
driver.quit();
}
}
}
No comments:
Post a Comment