How do I find a particular link on a page with Selenium and Python?

How do I find a particular link on a page with Selenium and Python?

QA 0

When searching for a particular link on a page, it’s easy to store the link elements in a List, and then loop through it until you find a match:

Python Code

import win32com.client
x = win32com.client.Dispatch("AppRobotic.API")
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By

# navigate to Yahoo
driver = webdriver.Firefox()
driver.get('https://www.yahoo.com')
# sleep 1 second
x.Wait(1000)

# Loop through all links, click them, and return to previous page
myList = driver.find_elements_by_css_selector("div.classname a")
for i in range(len(myList)):
element = driver.find_elements_by_css_selector("div.classname a")[i]
element.click()
driver.back()