
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Verify Tooltip Using Selenium WebDriver
We can verify the tooltip of an element using Selenium webdriver using the getAttribute method. A tooltip text is the one which gets displayed while we hover on that element.
It disappears once we move the mouse away from the element. A tooltip text generally displays the title attribute value of an element. First, we identify the element then apply the getAttribute method on it. The parameter to be passed to this method is title.
Let us investigate the html code of an element - Tools having a tooltip text.
Here, the tooltip text displayed from Tools menu is Tools - Online Development and Testing Tools which is the value set for the title attribute in the html.
Example
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; public class TooltipVerfy{ public static void main(String[] args) { System.setProperty("webdriver.gecko.driver", "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe"); WebDriver driver = new FirefoxDriver(); //implicit wait driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); //URL launch driver.get("https://www.tutorialspoint.com/index.htm"); //identify element WebElement n = driver.findElement(By.linkText("Tools")); //obtain title attribute String s = n.getAttribute("title"); //verify tooltip text if(s.equals("Tools - Online Development and Testing Tools")) { System.out.println("Tooltip text matched"); }else{ System.out.println("Tooltip text not matched"); } driver.quit(); } }
Output
Advertisements