Selenium Class Name Locator

Identifying the WebElement by “CLASS_NAME” locator value.It takes String as an argument. If element doesn’t identified it throws an exception as NoSuchElementException

Syntax: driver.find_element(By.CLASS_NAME,"locator_value")
By ClassName

Example: In the below example we will launch the webpage and enter the text in the edit box using CLASS_NAME locator value.

  


ClassName_Locator.py

from selenium import webdriver
import time

from selenium.webdriver.common.by import By

driver = webdriver.Chrome("/Users/admin/Documents/Skill2Lead/Others/drivers/chromedriver.exe")

driver.get("http://www.dummypoint.com/seleniumtemplate.html")
time.sleep(2)

ele = driver.find_element(By.CLASS_NAME,"entertext")
ele.send_keys("Skill2Lead_ClassName")

# OR

driver.find_element(By.CLASS_NAME,"entertext").send_keys("Skill2Lead_ClassName")

time.sleep(5)
driver.quit()