Created
March 9, 2020 18:47
-
-
Save pakoy3k/4e425306d85a6fb57d0173f03dc11035 to your computer and use it in GitHub Desktop.
Seleniun test with chrome, count all links "href" and validate the status
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
#pip install selenium | |
#pip install requests | |
#pip install chromedriver | |
# dev -> @pakoy3k | |
from selenium import webdriver | |
import time | |
import requests | |
options = webdriver.ChromeOptions() | |
driver = webdriver.Chrome(chrome_options=options) | |
driver.get("http://gortsolutions.com") | |
time.sleep(5) | |
Links = driver.find_elements_by_css_selector("a") | |
i = 0 | |
for link in Links: | |
web = link.get_attribute('href') | |
if web is not None: | |
if "http" in web: | |
print(i) | |
i = i + 1 | |
r = requests.head(link.get_attribute('href')) | |
print(link.get_attribute('href'), r.status_code) | |
driver.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment