zoukankan      html  css  js  c++  java
  • Python 安装 selenium 与 chromedriver.exe

    1. Python安装selenium
      进入cmd,输入:pip3 install selenium (有时受到用户权限限制,输入:pip3 install --user selenium)

    2. 安装chromedriver.exe
      在链接 http://chromedriver.storage.googleapis.com/index.html 选择合适版本的chromedriver.exe,
      下载chromedriver_win32.zip,即使电脑中安装的是x64的chrome浏览器也没有任何关系。
      解压后将chromedriver.exe放到chrome浏览器的安装路径中(例如:C:Program Files (x86)GoogleChromeApplication)
      并将该安装路径添加到系统环境变量Path中

    3. 在编写test_selenium.py代码,内容如下,

    # coding=utf-8
    from selenium import webdriver
    from selenium.common.exceptions import NoSuchElementException
    from selenium.webdriver.common.keys import Keys
    import time
    browser = webdriver.Chrome() # Get local session of Chrome
    browser.get("http://www.yahoo.com") # Load page
    assert "Yahoo!" in browser.title
    elem = browser.find_element_by_name("p") # Find the query box
    elem.send_keys("seleniumhq" + Keys.RETURN)
    time.sleep(0.2) # Let the page load, will be added to the API
    try:
        browser.find_element_by_xpath("//a[contains(@href,'http://seleniumhq.org')]")
    except NoSuchElementException:
        assert 0, "can't find seleniumhq"
        browser.close()
    

    运行test_selenium.py,如果安装正确,则会开启chrome浏览器,并打开了http://www.yahoo.com页面

  • 相关阅读:
    使用SpringAOP
    Alpha 冲刺 (5/10)
    Alpha 冲刺 (4/10)
    Alpha 冲刺 (3/10)
    Alpha 冲刺 (2/10)
    Alpha 冲刺 (1/10)
    项目需求分析答辩总结
    项目UML设计(团队)
    项目选题报告答辩总结
    第七次作业--项目需求分析
  • 原文地址:https://www.cnblogs.com/lqqgis/p/12641540.html
Copyright © 2011-2022 走看看