zoukankan      html  css  js  c++  java
  • 2-8 如何使用Expected_conditions判断元素是否可见

    from selenium import webdriver
    import time
    #导入expected_conditions预期包判断标题是否正确:
    from selenium.webdriver.support import expected_conditions as EC
    #导入WebDriverWait
    from selenium.webdriver.support.wait import WebDriverWait
    #导入by:
    from selenium.webdriver.common.by import By
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.get("http://www.5itest.cn/register")
    # EC.title_is #title_is代表现在的title和预期的title是一样的
    time.sleep(5)
    print(EC.title_contains("注册")) #title_contains代表只要包含就可以了
    # element = driver.find_element_by_class_name("controls")
    #拿到By定位的元素:
    locator = (By.CLASS_NAME,"controls")
    #visibility_of_element_located使用可见度/是否可见:
    # EC.visibility_of_element_located(element)
    #使用WebDriverWait的until寻找父级元素:
    WebDriverWait(driver,1).until(EC.visibility_of_element_located(locator))
    #关闭driver可以有效避免电脑和浏览器卡顿:
    driver.close()
    #presence_of_element_located元素的存在位置:
    EC.presence_of_element_located()
    #使用id进行定位邮箱地址:
    # driver.find_element_by_id("register_email").send_keys("1320685524@qq.com")
    #使用class定位用户名、find_elements_by_class_name返回的是列表、列表才可以len、先定义父类、再定义子类:
    # user_name_element_node = driver.find_elements_by_class_name("controls")[1]
    # user_element = user_name_element_node.find_element_by_class_name("form-control")
    # user_element.send_keys("dsads")
    #使用name定位密码:
    # driver.find_element_by_name("password").send_keys("990496256dd")
    #使用xpath定位验证码:
    # driver.find_element_by_xpath('//*[@id="captcha_code"]').send_keys("111111")
  • 相关阅读:
    解决Android中无法搜索联系人的问题
    在InstallShield中发布单一的Setup.exe文件
    log4net使用简介
    h264格式的flv和mkv无损转换成mp4的方法
    使用boost.filesystem进行文件操作
    Tcp连接的七次握手浅析
    Android ICS系统是支持通过互联网时间同步的
    解决从其它搜索引擎不能直接访问百度页面的问题
    _ttoi 代替atoi
    windows 下VLC播放器应用之二LIBVLC API解析
  • 原文地址:https://www.cnblogs.com/zhang-da/p/12128964.html
Copyright © 2011-2022 走看看