我有一个'WedDriverWait',用于表示元素是否存在,如果页面正确加载,则工作正常,但偶尔页面无法加载(我只是得到一个空白页面),然后“ wait”大约5分钟,然后我将其设置为45秒。
代码:
import selenium
import random
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
import time
import pyautogui
driver = webdriver.Chrome()
driver.get('some webpage')
WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR,'body > div.content.login > div.wrap > div')))
elem2 = driver.find_element_by_id ('data_body')
compa = elem2.text
if compa:
name()
click()
time.sleep(8)
driver.switch_to_window(driver.window_handles[1])
try:
WebDriverWait(driver, 45).until(EC.presence_of_element_located((By.CSS_SELECTOR,'something')))
login()
except Exception:
closing_page()
else:
moveon()