微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

隐式等待的两种写法

#-*- 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")

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐