Hello friends
In this Article we will learn that how to handle the tooltip operation in selenium, so while automating your website you will get 2 kind of below scenarios :-
1). Tool tip in title tag :- We will use getAttribute("title")
2). Tool tip inside div or any other html tag :- we will use here actions class.
Here is the code for both
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class Tooltiptest {
WebDriver driver;
@BeforeTest
public void g() throws InterruptedException
{
/*System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\Complete selenium\\ChromeDriver\\83\\chromedriver.exe");
System.setProperty("webdriver.chrome.silentOutput", "true");
driver = new ChromeDriver();*/
System.setProperty("webdriver.gecko.driver", "D:\\Selenium\\geckodriver\\new\\geckodriver.exe");
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "null");
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.navigate().to("file:///D:/Selenium/Complete%20selenium/tooltip/tooltip.html");
Thread.sleep(3000);
}
@Test
public void gettootltip() throws InterruptedException
{
WebElement tootipelement = driver.findElement(By.className("tooltip"));
Actions action = new Actions(driver);
action.moveToElement(tootipelement).build().perform();
String text = driver.findElement(By.className("tooltiptext")).getText();
System.out.println(text);
Thread.sleep(3000);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
WebElement element = driver.findElement(By.xpath("/html/body/form/input[1]"));
String text2 = element.getAttribute("title");
System.out.println(text2);
}
}
No comments:
Post a Comment