I have a python script written to load 'http://httpfoerver.com' to redirect to a captive portal, then some implicit wait functions to wait for the login boxes and login button elements.
I know the code works because i've tried it when I'm already logged in and connected to the internet, and it successfully completes the login portal (when I manually redirect to it).
However when I first join the network and try to run the script, it hangs on loading and starting the chrome webdriver (I know this based on the traceback when I press ctrl+c). I think it may have something to do with waiting for internet or for the page to load, however I am not interested in either as I just need it to launch and wait for a few html elements.
Does anyone know what could be happening, or have any flags I could pass to the webdriver to make it ignore the status of my internet connection?
Code I'm using:
import sys
import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import NoSuchElementException
def implicit_wait_byid(driver, element):
try:
item = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, element))
)
return item
except NoSuchElementException:
sys.exit("Error loading page content. Please try again.")
def implicit_wait_byname(driver, element):
try:
item = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.NAME, element))
)
return item
except NoSuchElementException:
sys.exit("Error loading page content. Please try again.")
def implicit_wait_byxpath(driver, element):
try:
item = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, element))
)
return item
except NoSuchElementException:
sys.exit("Error loading page content. Please try again.")
chrome_options = Options()
# chrome_options.add_argument("--headless")
# chrome_options.binary_location = "/usr/bin/chromedriver"
# chrome_options.add_argument("--disable-dev-shm-usage")
# chrome_options.add_argument("--no-sandbox")
chrome_options.page_load_strategy = 'none'
driver = webdriver.Chrome(options=chrome_options) # code stops here without internet, with internet it runs fine.
driver.get("http://httpforever.com")
implicit_wait_byname(driver, "name").send_keys("d")
implicit_wait_byname(driver, "email").send_keys("[email protected]")
implicit_wait_byname(driver, "auth_method").click()
exit(0)
Chrome version and webdriver version are 116. Python is version 3.11.3.
I've tried different flags, and changing the page loading strategy.