zoukankan      html  css  js  c++  java
  • selenium3打开chrome浏览器,firefox

    import os
    from selenium import webdriver
    
    chromedriver = "C:Program Files (x86)GoogleChromeApplicationchromedriver.exe"
    os.environ["webdriver.chrome.driver"] = chromedriver
    driver = webdriver.Chrome(chromedriver)
    
    driver.get("http://www.baidu.com")
    
    driver.find_element_by_id("kw").send_keys("Selenium2")
    driver.find_element_by_id("su").click()
    

      

    import os
    from selenium import webdriver

    chromedriver = "C:Program Files (x86)GoogleChromeApplicationchromedriver.exe"
    os.environ["webdriver.chrome.driver"] = chromedriver
    driver = webdriver.Chrome(chromedriver)

    driver.get("http://www.baidu.com")

    driver.find_element_by_id("kw").send_keys("Selenium2")
    driver.find_element_by_id("su").click()

    selenium.common.exceptions.WebDriverException: Message: Expected browser binary location, but unable to find binary in default location, 
    no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line

    指定Firefox浏览器程序路径

    from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

    binary = FirefoxBinary('path')

    driver = webdriver.Firefox(firefox_binary=binary)

    driver.get("http://www.baidu.com")

    driver.find_element_by_id("kw").send_keys("Selenium2")
    driver.find_element_by_id("su").click()

     浏览器记录密码,加载配置免登陆:

    1.Firefox

    profileDir = r'C:UsersAdministratorAppDataRoamingMozillaFirefoxProfileshkehfoij.default'

    profile = webdriver.FirefoxProfile(profileDir)

    driver = webdriver.Firefox(profile)

    2.Chrome

    option = webdriver.ChromeOptions()

    option.add_argument('--usr-data-dir=C:UsersAdministratorAppDataLocalGoogleChromeUser Data')

    driver = webdriver.Chrome(chrome_options=option)

    谷歌驱动下载地址:

    http://chromedriver.storage.googleapis.com/index.html

    对应版本:

    v2.21  v46-50

    v2.22  v49-52

    v2.23  v51-53

    v2.24  v52-57

    v2.25  v53-55

    v2.26  v53-55

    v2.27  v54-56

    v2.28  v55-57

    v2.29  v56-58

    ---by littleyang 测试就是测试一下
  • 相关阅读:
    UIView+ViewController.h 点击控制器上视图,使视图push下个视图控制的封装
    Touch Demo
    layoutSubviews与drawRect
    UI NS CG CF 区别
    CALayer
    关于CALayer的困惑
    pypy 对接阿里短信平台
    mysql去掉默认值
    GCC升级
    jemalloc 测试
  • 原文地址:https://www.cnblogs.com/littleyang/p/6530165.html
Copyright © 2011-2022 走看看