简体   繁体   English

Python:Function相当于firefoxdriver中的chromedriver。 chromedriver --> firefoxdriver(firefoxdriver 给我语法错误)

[英]Python: Function equivalent to chromedriver in firefoxdriver. chromedriver --> firefoxdriver (firefoxdriver gives me syntax error)

I have this two functions:我有这两个功能:

def get_chromedriver(headless = False):
    import os
    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    options = Options()
    options.binary_location = '/usr/bin/google-chrome'
    options.add_argument('user-data-dir=' + os.environ['HOME'] + '/.config/chromedriver')
    options.add_experimental_option('detach', True)
    options.add_experimental_option('excludeSwitches', ['enable-automation'])
    options.add_experimental_option('useAutomationExtension', False)
    options.headless = headless
    driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver', options=options)
    return driver

def get_firefoxdriver(headless = False):
    import os
    from selenium import webdriver
    from selenium.webdriver.firefox.options import Options
    options = Options()
    options.binary_location = '/usr/bin/firefox'
    options.add_argument('user-data-dir=' + os.environ['HOME'] + '/.config/firefoxdriver')
    options.add_experimental_option('detach', True)
    options.add_experimental_option('excludeSwitches', ['enable-automation'])
    options.add_experimental_option('useAutomationExtension', False)
    options.headless = headless
    driver = webdriver.Firefox(executable_path='/usr/bin/geckodriver', options=options)
    return driver

get_chromedriver function works perfectly but not get_firefoxdriver, which is a copy of the get_chromedriver function. get_chromedriver function 可以完美运行,但 get_firefoxdriver 不能,它是 get_chromedriver function 的副本。
How can I make the get_firefoxdriver function functionally equivalent to the get_chromedriver function, except for the paths, the webdriver and the browser used?如何使 get_firefoxdriver function 在功能上等同于 get_chromedriver function,除了使用的路径、webdriver 和浏览器?

Firefox webdriver does not have the same instance methods as the Chrome webdriver. Firefox webdriver 没有与 Chrome webdriver 相同的实例方法。 I see that in your Firefox driver creation function you are calling "detach" and "exludeSwitches" options, however if you take a look at the Firefox documentation you won't find those options whereas the same are available in the Chrome documentation .我看到在您的 Firefox 驱动程序创建 function 中,您正在调用“分离”和“exludeSwitches”选项,但是如果您查看 Z763F7F1AEC350CD1A46238D1D5C3C29 选项,则在 Chrome 文档中找到相同的可用文档选项。

There are pros and cons in using each driver, and as in every case the solution should match the use case.使用每个驱动程序都有利有弊,并且在每种情况下,解决方案都应与用例相匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Selenium 运行 ChromeDriver 和 FirefoxDriver 的问题 - Issues running ChromeDriver and FirefoxDriver with Selenium 硒上传文件java ChromeDriver / FirefoxDriver - selenium upload file java ChromeDriver/FirefoxDriver 检查是否通过系统属性安装了FirefoxDriver或ChromeDriver? - Check if FirefoxDriver or ChromeDriver is installed via system properties? FirefoxDriver提供NullPointerException - FirefoxDriver gives NullPointerException 如何在Selenium WebDriver中对FirefoxDriver,ChromeDriver和IEdriver执行基本身份验证? - How to perform Basic Authentication for FirefoxDriver, ChromeDriver and IEdriver in Selenium WebDriver? Selenium WebDriver C#完整网站截图使用ChromeDriver和FirefoxDriver - Selenium WebDriver C# Full Website Screenshots With ChromeDriver and FirefoxDriver 从FireFoxDriver切换到ChromeDriver会导致某些元素加载错误(硒) - Switching from FireFoxDriver to ChromeDriver cause some element loading errors (Selenium) 没有它的GUI(无头模式)在Selenium上运行ChromeDriver或FirefoxDriver - Running ChromeDriver or FirefoxDriver on Selenium without it's GUI (headless mode) Selenium FirefoxDriver在Headless中获取错误 - Selenium FirefoxDriver in Headless get error 创建FirefoxDriver时发生硒测试错误 - Selenium test error on FirefoxDriver creation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM