Selenium is an open-source web-based automation tool. In this answer, we learn how to verify the tooltip using the Selenium web driver in Python.
The tooltip is the text that displays on the screen when we hover on the element. It provides more information about that element for users. We can verify the tooltip by getting the value of the title
attribute using the get_attribute()
method.
element.get_attribute("title")
Let's take a look at an example of this.
from selenium import webdriverimport time#Specify where the Chrome driver present in our PCPATH=r"C:\Users\educative\Documents\chromedriver\chromedriver.exe"#Getting an instance of the web driverdriver = webdriver.Chrome(PATH)#Providing the website URLdriver.get("https://www.educative.io/")#Getting the elementele = driver.find_element("xpath",'//*[@id="__next"]/div[2]/nav/a')#Checking if the tooltip text matchesif ele.get_attribute("title") == "educative.io":print("Tooltip is matched")else:print("Tooltip text is not matched")
webdriver
from the selenium
package.time
.chromedriver.exe
in the Windows environment.webdriver
.driver.get()
method to open it.find_element()
method.get_attribute()
method, and compare it with a known value. We print the output according to the result of the comparison.Free Resources