• 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 测试就是测试一下
  • 相关阅读:
    POJ 1016 不断压缩字符串判断三种结果
    递归的运行机制简单理解
    模拟链表
    输入两个字符串,不用系统提供的函数strcat,自定义函数将两个字符串连接起来。
    信号量多线程同步
    windows 多线程同步技术
    qsort和sort的区别(转)
    大数阶乘位数
    字符串数组qsort排序
    Safecracker
  • 原文地址:https://www.cnblogs.com/littleyang/p/6530165.html
Copyright © 2020-2023  润新知