简体   繁体   中英

Python selenium webdriver explicit wait connection error

The script I am running does not return consistent data from run to run. I believe as I iterate through pages, it is not waiting for all pages to load Javascript and AJAX in full. In an attempt to remedy this I added the explicit wait below, but it returns the following error:

ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

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

browser = webdriver.Chrome()
url = 'http://www.website.com'
browser.get(url)
try:
    element = WebDriverWait(browser, 10).until(EC.presence_of_all_elements_located((By.ID, "results-main")))
finally:
    browser.quit()

print (browser.page_source)

An implicit wait will run without errors, but it also does not return consistent source code.

Im assuming you are getting this exception at browser.page_source This is because you are doing browser.quit Quit() - It is used to shut down the web driver instance or destroy the web driver

you will need to get the page source before you quit either by adding the print statement at the end of your try block or moving the quit after you print :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM