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 测试就是测试一下
  • 相关阅读:
    .net注册iis
    hdu 1081To The Max
    hdu 1312Red and Black
    hdu 1016Prime Ring Problem
    hdu 1159Common Subsequence
    hdu 1372Knight Moves
    hdu 1686Oulipo
    hdu 1241Oil Deposits
    hdu 1171Big Event in HDU
    hdu 4006The kth great number
  • 原文地址:https://www.cnblogs.com/littleyang/p/6530165.html
Copyright © 2011-2022 走看看