Class Name Locator
Locating an element by using value
of Class attribute of the webelement.
Scenario :
Click on the Signin
button.
Close the browser
Following is the steps to locate the element using Class Name
property on webpage.
1 Right click on Sign in webelement on the page and select inspect
option in the context menu
Pick the class attribute value
of the element.
Syntax for locating a web
element using its Class Name attribute is written as:
driver.find_element(By.CLASS_NAME,<className
Value>)
or
driver.find_element_by_class_name(<className
Value>)
Below is the 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_class_name("signin").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_class_name("signin").click()
Note: If there are multiple elements with the same Class Name
locator then the first element on the page is selected. Test may fail, if
another element with the same Class Name locator is present on the web page.
Comments
Post a Comment