隐式等待的两种写法

#-*- coding:utf-8 -*-

from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait

#隐式等待方法1
def credit1(username):
    driver = webdriver.Chrome()
    driver.get("http://credit.risk.jc.learn.com/loan-credit/user/caslogin")
    driver.maximize_window()
    WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id("username")).send_keys(username)
    WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id("pwd")).send_keys("Cs654321")
    WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_class_name("btn")).click()









from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC  # 设置等待执行语句


#隐式等待方法2
def credit2(username):
    driver = webdriver.Chrome()
    driver.get("http://credit.risk.jc.learn.com/loan-credit/user/caslogin")
    driver.maximize_window()
    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'username'))).send_keys(username)
    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'pwd'))).send_keys("Cs654321")
    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, 'btn'))).click()



# credit1("11041433")
credit2("11041433")

 

posted @ 2019-07-29 21:52  不不田鼠  阅读(543)  评论(0编辑  收藏  举报