zoukankan      html  css  js  c++  java
  • WebDriver 中常用方法4---获取验证信息(虫师《selenium3自动化测试实战--基于Python语言笔记16》)

    1.title:用于获取当前页面的标题

    2.current_url:用于获取当前页面的URL

    3.text:用于获取当前页面的文本信息

    from time import sleep
    from selenium import webdriver
    
    driver = webdriver.Chrome()
    driver.get("https://www.baidu.com")
    print("Before search ===========")
    
    # 打印当前页面title
    title = driver.title
    print("title:" + title)
    
    # 打印当前页面URL
    now_url = driver.current_url
    print("URL:" + now_url)
    
    driver.find_element_by_id("kw").send_keys("selenium")
    driver.find_element_by_id("su").click()
    sleep(2)
    
    print("After search =========")
    
    # 再次打印当前页面title
    title = driver.title
    print("title:" + title)
    
    # 再次打印当前页面url
    now_url = driver.current_url
    print("URL:" + now_url)
    
    # 获取搜索结果条数
    num = driver.find_element_by_class_name('nums').text
    print("result:" + num)
    
    driver.quit()

    运行结果为:

    Before search ===========
    title:百度一下,你就知道
    URL:https://www.baidu.com/
    After search =========
    title:selenium_百度搜索
    URL:https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu&wd=selenium&rsv_pq=e09374d700008cca&rsv_t=5f46bEZRwZ5%2FiIAQaCiFjjhcQGNv3cUU34RQnx3AodW5SloTz%2BubhS%2BPO%2Bg&rqlang=cn&rsv_enter=0&rsv_dl=tb&rsv_sug3=8&inputT=133&rsv_sug4=133
    result:搜索工具
    百度为您找到相关结果约27,500,000个
  • 相关阅读:
    Java web学习总结
    java web知识点
    SSH进阶之路
    file /etc/httpd/conf.d/php.conf from install of php-5.6.37-1.el7.remi.x86_64 conflicts with file from package mod_php71w-7.1.18-1.w7.x86_64
    centos7上安装php5.6
    centos7 删除php
    centos7删除yum安装的php
    给服务器加内存
    Hyperledger Fabric 开发环境搭建 centos7系统
    79
  • 原文地址:https://www.cnblogs.com/kite123/p/11480208.html
Copyright © 2011-2022 走看看