zoukankan      html  css  js  c++  java
  • python selenium 相关操作

    selenium :

      是一个用于Web应用程序测试的工具。Selenium测试直接运行在浏览器中,就像真正的用户在操作一样。支持的浏览器包括IE(7, 8, 9, 10, 11),Mozilla Firefox,Safari,Google Chrome,Opera等。这个工具的主要功能包括:测试与浏览器的兼容性——测试你的应用程序看是否能够很好得工作在不同浏览器和操作系统之上。测试系统功能——创建回归测试检验软件功能和用户需求。支持自动录制动作和自动生成 .Net、Java、Perl等不同语言的测试脚本。

    据 Selenium 主页所说,与其他测试工具相比,使用 Selenium 的最大好处是:
    Selenium 测试直接在浏览器中运行,就像真实用户所做的一样。Selenium 测试可以在 Windows、Linux 和 Macintosh上的 Internet Explorer、Chrome和 Firefox 中运行。其他测试工具都不能覆盖如此多的平台。使用 Selenium 和在浏览器中运行测试还有很多其他好处。
    下面是主要的两大好处:
    通过编写模仿用户操作的 Selenium 测试脚本,可以从终端用户的角度来测试应用程序。通过在不同浏览器中运行测试,更容易发现浏览器的不兼容性。Selenium 的核心,也称browser bot,是用 JavaScript 编写的。这使得测试脚本可以在受支持的浏览器中运行。browser bot 负责执行从测试脚本接收到的命令,测试脚本要么是用 HTML 的表布局编写的,要么是使用一种受支持的编程语言编写的。
     
    Selenium 2.0适用于以下浏览器 [2]  :
    • Google Chrome
    • Internet Explorer 7, 8, 9, 10, 11
    • Firefox
    • Safari
    • Opera
    • HtmlUnit
    • phantomjs
    • Android
    • iOS
    Selenium 1.0适用于以下浏览器:
    Browser
    Selenium IDE
    Selenium Remote Control
    Selenium Core
    Selenium 2/Webdriver API
    Firefox 10
    Record and playback tests
    Start browser, run tests
    Run tests
    Run tests
    Firefox 9
    Record and playback tests
    Start browser, run tests
    Run tests
    Run tests
    Firefox 8
    Record and playback tests
    Start browser, run tests
    Run tests
    Run tests
    Firefox 7
    Record and playback tests
    Start browser, run tests
    Run tests
    Run tests
    Firefox 6
    Record and playback tests
    Start browser, run tests
    Run tests
    Run tests
    Firefox 5
    Record and playback tests
    Start browser, run tests
    Run tests
    Run tests
    Firefox 4
    Record and playback tests
    Start browser, run tests
    Run tests
    Run tests
    Firefox 3.6
    Record and playback tests
    Start browser, run tests
    Run tests
    Run tests
    Firefox 3
    Record and playback tests
    Start browser, run tests
    Run tests
    not supported
    IE 9
    not supported
    Start browser, run tests
    Run tests
    Run tests
    IE 8
    not supported
    Start browser, run tests
    Run tests
    Run tests
    IE 7
    not supported
    Start browser, run tests
    Run tests
    Run tests
    Safari 3
    not supported
    Start browser, run tests
    Run tests
    not supported
    Safari 2
    not supported
    Start browser, run tests
    Run tests
    not supported
    Opera 9
    not supported
    Start browser, run tests
    Run tests
    Run tests
    Opera 8
    not supported
    Start browser, run tests
    Run tests
    Run tests
    Chrome
    not supported
    Start browser, run tests***
    Run tests***
    Run tests***
    Others
    not supported
    Partial support possible*
    Run tests**
    not supported

    selenium相关操作

    安装: pip  install  selenium

    支持的浏览器:

      

    导入模块:

    from selenium  import webdriver

    浏览器插件(谷歌):链接:https://pan.baidu.com/s/17xk-6GXeach_HZTWo-AUqg 
    提取码:vdlj 

    启动浏览器:

    bro = webdriver.Chrome(executable_path = r"F:chromedriver.exe")
    

    模拟请求地址:

    bro.get("https://koudashijie.com/teachers/classes")
    

    找到输入框,拿到前端页面ID

    text_input = bro.find_element_by_id('kw')
    

    输入内容

    text_input.send_keys("蒸汽创客")
    

    模拟提交按钮

    login_btn = bro.find_element_by_id("su").click()
    

    拿到页面

    bro.page_source
  • 相关阅读:
    crystal report 用存储过程的问题。
    新的开始—2014
    C#基础(二)——C#中的构造函数
    C#基础(一)——C#中反斜杠/n与/r的区别
    Html基础(一)
    yield关键字, default关键字, 别名关键字
    让 wpf tabcontrol 延缓初始化每个tab item content
    MVC,MVP,MVVM(补充)
    Focus scope in WPF
    Wpf ItemsControl 开启UI Virtualization 的条件
  • 原文地址:https://www.cnblogs.com/wqzn/p/11130001.html
Copyright © 2011-2022 走看看