Created
June 1, 2017 20:11
-
-
Save pottedmeat7/15f60f57e557667e1ab3a9f8e88bd62e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 selenium.webdriver.common.by import By | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.support.ui import Select | |
from selenium.common.exceptions import NoSuchElementException | |
import unittest, time, re, sys | |
filepath = sys.argv[1] | |
class Openlinksinfile(unittest.TestCase): | |
def setUp(self): | |
self.driver = webdriver.Firefox() | |
self.driver.implicitly_wait(30) | |
self.base_url = "" | |
self.verificationErrors = [] | |
self.accept_next_alert = True | |
self.links = [] | |
def test_clickalllinksonpage(self): | |
driver = self.driver | |
with open(filepath) as f: | |
links = f.readlines() | |
size = len(links) | |
print(size) | |
for i in range(0, size-1): | |
driver.get(links[i]) | |
title = str(driver.title) | |
print(links[i]) | |
print(title) | |
print("") | |
self.driver.implicitly_wait(30) | |
def is_element_present(self, how, what): | |
try: self.driver.find_element(by=how, value=what) | |
except NoSuchElementException, e: return False | |
return True | |
def is_alert_present(self): | |
try: self.driver.switch_to_alert() | |
except NoAlertPresentException, e: return False | |
return True | |
def close_alert_and_get_its_text(self): | |
try: | |
alert = self.driver.switch_to_alert() | |
alert_text = alert.text | |
if self.accept_next_alert: | |
alert.accept() | |
else: | |
alert.dismiss() | |
return alert_text | |
finally: self.accept_next_alert = True | |
def tearDown(self): | |
self.driver.quit() | |
self.assertEqual([], self.verificationErrors) | |
if __name__ == "__main__": | |
unittest.main(argv=[sys.argv[0]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment