-
-
Save tspspi/98c63d56c4b7a9ed1a57832e1672e7cc to your computer and use it in GitHub Desktop.
Simple Selenium project using chrome webdriver in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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