zoukankan      html  css  js  c++  java
  • time,implicitly_wait,WebDriverWait三种等待方式

    from selenium import webdriver
    from selenium.webdriver.support.wait import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC   #期望条件
    from selenium.webdriver.common.by import By   #八种定位方式
    
    
    '''
    三种等待方式
    seleep        一直等待
    driver.implicitly_wait(30)  全局隐性等待,不会一直等待,待加载后就往下执行
    WebDriverWait 显性等待
    '''
    
    #创建浏览器驱动
    driver = webdriver.Chrome(service_log_path='E:chrome.log')
    # driver.implicitly_wait(30)
    #访问一个网站
    driver.get('http://www.baidu.com')
    
    #点击百度网站的登录按钮
    driver.find_element_by_xpath('//div[@id="u1"]//a[@name="tj_login"]').click()
    
    # driver.find_element_by_id('TANGRAM__PSP_11__footerULoginBtn').click()
    
    #这句话的意思是:等待10秒钟的时间,每一秒去检查一次,一直到显示id这个定位元素出现,
    # (注:期望值,放置元素定位类型和元素定位表达式,所以用元组的形式传递)
    WebDriverWait(driver,5,1).until(EC.visibility_of_element_located((By.ID,'TANGRAM__PSP_11__footerULoginBtn')))
    
    #直到可见
    # WebDriverWait(driver,7,1).until(EC.presence_of_element_located((By.ID,'TANGRAM__PSP_11__footerULoginBtn')))
    
    #直到可点击
    # WebDriverWait(driver,7,1).until(EC.element_to_be_clickable((By.ID,'TANGRAM__PSP_11__footerULoginBtn')))
    driver.find_element_by_id('TANGRAM__PSP_11__footerULoginBtn').click()
    
    '''
    再iframe里面的内容直接查找是不可以的,需要切换到iframe才能查找
    '''
    driver.switch_to.frame()
  • 相关阅读:
    C# Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
    C# Collection was modified;enumeration operation may not execute
    C# 写文件
    AJAX 入门教程
    ABP 软删除ISoftDelete
    C# 随机列表
    C# ConfigurationManager 类的使用
    mui 关闭当前窗口
    C# 委托
    VSTO:使用C#开发Excel、Word【13】
  • 原文地址:https://www.cnblogs.com/TKOPython/p/13550615.html
Copyright © 2011-2022 走看看