Skip to content

Instantly share code, notes, and snippets.

@tspspi
Created February 11, 2020 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tspspi/98c63d56c4b7a9ed1a57832e1672e7cc to your computer and use it in GitHub Desktop.
Save tspspi/98c63d56c4b7a9ed1a57832e1672e7cc to your computer and use it in GitHub Desktop.
Simple Selenium project using chrome webdriver in Python
from selenium import webdriver
from time import sleep
class TestProg():
def __init__(self):
self.driver = webdriver.Chrome()
def runTest(self):
self.driver.get("https://slashdot.org/")
sleep(5)
try:
cookieAccept = self.driver.find_element_by_xpath('//*[@id="cmpwelcomebtnyes"]/a')
cookieAccept.click()
sleep(1)
except Exception:
sleep(1)
titles = self.driver.find_elements_by_class_name("story-title")
for titleObject in titles:
titleLinkObject = titleObject.find_element_by_tag_name('a')
titleText = titleLinkObject.text
hrefText = titleLinkObject.get_attribute('href')
print(titleText + " at " + hrefText)
testProgram = TestProg()
testProgram.runTest()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment