[Python] Selenium can't find element on server, but can on local device

Discussão em 'Python' iniciado por Stack, Novembro 28, 2024.

  1. Stack

    Stack Membro Participativo

    I'm trying to write a python script that will go to a website I host, wait for the external java script file to load, and then retrieve some elements that it creates. And it works great on my machine, but when I run it on pythonanywhere, it gives me this error:

    Traceback (most recent call last):
    File "/home/SmallCoder14/orthodox_saints_of_the_day/get_quotes.py", line 14, in <module>
    quote = WebDriverWait(driver, 10).until(
    File "/usr/local/lib/python3.10/site-packages/selenium/webdriver/support/wait.py", line 89, in until
    raise TimeoutException(message, screen, stacktrace)
    selenium.common.exceptions.TimeoutException: Message:
    Stacktrace:
    #0 0x5f8f634cbe89 <unknown>



    My code is:

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

    options = webdriver.ChromeOptions()

    options.add_argument('--no-sandbox')
    options.add_argument("--headless")

    driver = webdriver.Chrome(options=options)
    driver.get("https://SmallCoder14.pythonanywhere.com/quote-of-the-day")

    quote = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.XPATH, "/html/body/div/p[1]"))
    )

    driver.quit()



    I tried using implicitly_wait for 10 seconds instead of WebDriverWait for 10 seconds, but that yielded the same error. I also tried adding the --disable-dev-shm-usage argument, but that also yielded the same error

    Continue reading...

Compartilhe esta Página