Skip to content

Instantly share code, notes, and snippets.

@tspspi

tspspi/TestProg.py Secret

Created Feb 11, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.