zoukankan      html  css  js  c++  java
  • Python+Selenium 自动化实现实例打开浏览器模拟进行搜索数据并验证

    #导入模块

    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys

    #启动火狐浏览器
    driver = webdriver.Firefox()

    #打开url
    driver.get("http://www.python.org")

    #添加断言
    assert "Python" in driver.title

    #开始定位
    elem = driver.find_element_by_name("q")

    #清除输入框数据
    elem.clear()

    #输入数据
    elem.send_keys("pycon")

    #模拟点击回车按钮
    elem.send_keys(Keys.RETURN)

    #添加断言验证
    assert "No results found." not in driver.page_source

    #关闭浏览器驱动
    driver.close()

  • 相关阅读:
    c++作业2 9.22
    c++作业1 9.22
    c++练习题2
    c++练习题1
    10.10作业3
    10.10作业2
    10.10作业 1
    9.22作业5
    9.22作业4
    9.22zuo
  • 原文地址:https://www.cnblogs.com/forcepush/p/6645291.html
Copyright © 2011-2022 走看看