John Smith John Smith - 3 months ago 6x
Python Question

Python Selenium

How do I use Python to simply find a link containing text/id/etc and then click that element?

My imports:

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys

Code to go to my URL:

browser = webdriver.Firefox() # Get local session of firefox
browser.get(myURL) # Load page
#right here I want to look for element containing "Click Me" in the text
#and then click it


Look at method list of WebDriver class -

For example, to find element by its ID and click it, the code will look like this

element = browser.find_element_by_id("your_element_id")