0
votes
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 

url = "https://www.electionreturns.pa.gov/General/OfficeResults?OfficeID=13&ElectionID=undefined&ElectionType=undefined&IsActive=1" 

options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument("--test-type")

driver = webdriver.Chrome(r"...\chromedriver.exe", options = options)
driver.get(url)


try: 
    element = WebDriverWait(driver,20).until(
            EC.visibility_of_element_located((By.XPATH, "/html/body/script[15]"))
            )

finally: 
    driver.quit()

Very new at this but I can't seem to figure this out between the Selenium doc, and StackO.

This raises the:

raise TimeoutException(message, screen, stacktrace)

TimeoutException

Again, new at this. I'm fairly sure the java script I want to access is src="/Scripts/AppScripts/GeneralController.js" (?v=1.2). Which has the xpath of /html/body/script[15]. However, my access method could be the mistake itself.

Any insight is appreciated. Thanks, C.

1
Why do you want to access the element with src="/Scripts/AppScripts/GeneralController.js?v=1.2? What is your next action? - DebanjanB
It's generating HTML that's spitting out the election results which I want to read in to BS4 for an election webscraper. - theyoungercyrus

1 Answers

0
votes

Script elements are in the DOM but without state for visibility.

You can check them with EC.presence_of_element_located

element = WebDriverWait(driver,20).until(
            EC.presence_of_element_located((By.XPATH, "/html/body/script[15]"))
            )