[英]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.