zoukankan      html  css  js  c++  java
  • Python之selenium调用EC琐碎

    Selenium里有一个excepted_conditions模块。我们经常要用到EC.title()或者EC.title_contains()来判定标题,疑惑的地方是在括号内放入什么内容,都会有返回结果,不直观!

     1 from selenium import webdriver
     2 from selenium.webdriver.support import expected_conditions as EC
     3 
     4 options = webdriver.ChromeOptions()
     5 options.add_argument('--headless') #无界面
     6 
     7 url = 'https://www.baidu.com'   #定义url
     8 driver = webdriver.Chrome(options=options)     #加载浏览器
     9 driver.get(url)                 #请求网页
    10 print(EC.title_contains(u'百度一下,你就知道')) #返回一窜字符 <selenium.webdriver.support.expected_conditions.title_contains object at 0x000002881A954A48>
    11 print(EC.title_contains(u'百度一下,你就知道')(driver)) #返回True
    12 print(EC.title_contains(u'川普是坨大便')) #返回一寸字符串 <selenium.webdriver.support.expected_conditions.title_contains object at 0x000001C06E494A08>
    13 print(EC.title_contains(u'川普是坨大便')(driver)) #返回false

    在判定的后面加上driver就会返回布尔值,这样就很直观了。

  • 相关阅读:
    第一章-实例7-猴子吃桃问题
    第一章-实例6-判断是否为闰年
    第一章-实例3-计算变量所占字节数
    IDEA学习笔记
    spring boot学习概要(尚硅谷)
    JSP动态WEB开发技术--第一章
    学习前端的准备任务
    cmd优化
    软件测试基础概念
    软件工程理论
  • 原文地址:https://www.cnblogs.com/mafu/p/14217158.html
Copyright © 2011-2022 走看看