Link Locator
Link locator applies only to hyperlink texts. The links on a web page can be identify
with the help of anchor tag (<a>). Other than <a> any other tags is not considered as a link
locator.
Scenario :
Click on the Create Account
Link.
Following is the steps to locate the element using Link on webpage.
Right click on Create
Account webelement on the page and
select inspect option in the context menu
Pick the text of Link tag
Syntax for locating a web element using its Link Text is written
as:
driver.find_element(By.LINK_TEXT,<linktext>)
or
driver.find_element_by_link_text(<linktext>)
Script:
from selenium
import webdriver
from selenium.webdriver.common.by import By
chromePath="C:\\BrowserDrivers\\chromedriver.exe"
driver=webdriver.Chrome(executable_path=chromePath)
driver.get("https://www.rediff.com/")
driver.find_element_by_link_text("Create Account").click()
from selenium.webdriver.common.by import By
chromePath="C:\\BrowserDrivers\\chromedriver.exe"
driver=webdriver.Chrome(executable_path=chromePath)
driver.get("https://www.rediff.com/")
driver.find_element_by_link_text("Create Account").click()
Note: If there are multiple elements with the same link text then
the first one will be selected. Link Text locator works only on links
(hyperlinks).
Comments
Post a Comment