Python Selenium WebDriver等待花费的时间更长,然后应该

时间:2019-03-20 09:38:47

标签: python selenium webdriverwait

我有一个'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()

0 个答案:

没有答案