To find an element by its class using Selenium WebDriver in Python, you can use the find_element_by_class_name method. Here’s an example:
from selenium import webdriver
# Create an instance of the WebDriver
driver = webdriver.Chrome()
# Navigate to a webpage
driver.get('https://github.codetryout.com/')
# Find an element by its class name
element = driver.find_element_by_class_name('example-class')
# Perform actions on the element
element.click()
# Close the WebDriver
driver.quit()
In the code above, replace ‘https://www.example.com’ with the URL of the webpage you want to navigate to. ‘example-class’ should be replaced with the actual class name of the element you want to find. Once you have found the element, you can perform various actions on it, such as clicking, sending keys, or extracting text.
Make sure you have the Selenium WebDriver for Python installed and the appropriate WebDriver executable for your browser (in this case, the Chrome WebDriver) available in your system’s PATH or specify its location in the code.