本文整理汇总了Python中selenium.webdriver.FirefoxOptions方法的典型用法代码示例。如果您正苦于以下问题:Python webdriver.FirefoxOptions方法的具体用法?Python webdriver.FirefoxOptions怎么用?Python webdriver.FirefoxOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver
的用法示例。
在下文中一共展示了webdriver.FirefoxOptions方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start_browser
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxOptions [as 别名]
def start_browser():
# Ensure mobile-friendly view for parsing
useragent = "Mozilla/5.0 (Linux; Android 8.0.0; Pixel 2 XL Build/OPD1.170816.004) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Mobile Safari/537.36"
#Firefox
profile = webdriver.FirefoxProfile()
profile.set_preference("general.useragent.override", useragent)
options = webdriver.FirefoxOptions()
options.set_preference("dom.webnotifications.serviceworker.enabled", False)
options.set_preference("dom.webnotifications.enabled", False)
options.add_argument('--headless')
browser = webdriver.Firefox(firefox_profile=profile,options=options)
return browser
# Login
示例2: _process_firefox_options
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxOptions [as 别名]
def _process_firefox_options(self, opts):
if isinstance(opts, FirefoxOptions):
options = opts
else:
options = FirefoxOptions()
if 'args' in opts:
for arg in opts.pop('args'):
options.add_argument(arg)
if opts.pop('headless', None) or self.options.pop('headless', None):
options.headless = True
if 'binary' in opts or 'binary_location' in opts:
options.binary = opts.pop('binary') or opts.pop('binary_location')
if 'prefs' in opts:
for name, value in opts.pop('prefs').items():
options.set_preference(name, value)
if 'proxy' in opts:
options.proxy = opts.pop('proxy')
if 'profile' in opts:
options.profile = opts.pop('profile')
if 'log_level' in opts:
options.log.level = opts.pop('log_level')
self.selenium_opts['options'] = options
示例3: setUp
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxOptions [as 别名]
def setUp(self):
opts = webdriver.FirefoxOptions()
opts.add_argument('headless')
self.driver = webdriver.Remote(command_executor = 'http://192.168.122.60:4444/wd/hub',
desired_capabilities = opts.to_capabilities())
开发者ID:PacktPublishing,项目名称:-Automating-Web-Testing-with-Selenium-and-Python,代码行数:7,代码来源:testAll_firefox.py
示例4: start_firefox
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxOptions [as 别名]
def start_firefox(url=None, headless=False, options=None):
"""
:param url: URL to open.
:type url: str
:param headless: Whether to start Firefox in headless mode.
:type headless: bool
:param options: FirefoxOptions to use for starting the browser.
:type options: :py:class:`selenium.webdriver.FirefoxOptions`
Starts an instance of Firefox. You can optionally open a URL::
start_firefox()
start_firefox("google.com")
The `headless` switch lets you prevent the browser window from appearing on
your screen::
start_firefox(headless=True)
start_firefox("google.com", headless=True)
For more advanced configuration, use the `options` parameter::
from selenium.webdriver import FirefoxOptions
options = FirefoxOptions()
options.add_argument("--width=2560")
options.add_argument("--height=1440")
start_firefox(options=options)
On shutdown of the Python interpreter, Helium cleans up all resources used
for controlling the browser (such as the geckodriver process), but does
not close the browser itself. If you want to terminate the browser at the
end of your script, use the following command::
kill_browser()
"""
return _get_api_impl().start_firefox_impl(url, headless, options)
示例5: _get_firefox_options
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxOptions [as 别名]
def _get_firefox_options(self, headless, options):
result = FirefoxOptions() if options is None else options
if headless:
result.headless = True
return result
示例6: setUp
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxOptions [as 别名]
def setUp(self):
firefox_options = webdriver.FirefoxOptions()
firefox_options.add_argument('headless')
self.driver = webdriver.Firefox(options=firefox_options)
开发者ID:PacktPublishing,项目名称:-Automating-Web-Testing-with-Selenium-and-Python,代码行数:6,代码来源:testAllFirefox.py
示例7: setUp
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxOptions [as 别名]
def setUp(self):
os.environ['MOZ_HEADLESS'] = '1'
# or use this:
# options = webdriver.FirefoxOptions()
# options.add_argument('headless')
self.client = webdriver.Firefox()
time.sleep(1)
if not self.client:
self.skipTest('Web browser not available.')
示例8: setUpClass
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxOptions [as 别名]
def setUpClass(cls):
super(SeleniumTestCase, cls).setUpClass()
# load the webdriver setting as late as possible
# this is needed when no web driver is specified and no functional tests should be run
from common.settings.webdriver import WEBDRIVER
if WEBDRIVER == "firefox":
firefox_opt = None
if settings.FUNCTESTS_HEADLESS_TESTING:
firefox_opt = webdriver.FirefoxOptions()
firefox_opt.headless = True
cls.selenium = webdriver.Firefox(firefox_options=firefox_opt)
elif WEBDRIVER == "chrome":
chrome_opt = None
if settings.FUNCTESTS_HEADLESS_TESTING:
chrome_opt = webdriver.ChromeOptions()
chrome_opt.headless = True
cls.selenium = webdriver.Chrome(options=chrome_opt)
elif WEBDRIVER == "safari":
# headless mode is not possible right now in Safari
# see https://github.com/SeleniumHQ/selenium/issues/5985
cls.selenium = webdriver.Safari()
else:
raise Exception("Webdriver not configured probably!")
cls.selenium.implicitly_wait(settings.FUNCTESTS_DEFAULT_WAIT_TIMEOUT)
示例9: __init__
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxOptions [as 别名]
def __init__(
self, preferred_browser="firefox", headless=True, chunk_size=DEFAULT_CSIZE
):
"""Initialize the downloader and set the default chunk size for the downloads
:param preferred_browser: "firefox" or "chrome". Browser to use for the downloader. Defaults to "firefox".
:param headless: Boolean. Hide/show the browser. Defaults to `True`.
:param chunk_size: Downloader chunks size in bytes. Defaults to 1MB.
"""
self.baseurl = "https://openload.co"
self._chunk_size = chunk_size
# TODO: check if chromedriver/geckodriver is already present, eventually ask the user if he wants the
# script to download it
if preferred_browser == "firefox":
if headless:
fox_opt = webdriver.FirefoxOptions()
fox_opt.add_argument("--headless")
self._browser = webdriver.Firefox(options=fox_opt)
else:
self._browser = webdriver.Firefox()
if preferred_browser == "chrome":
if headless:
chrome_opt = webdriver.ChromeOptions()
chrome_opt.add_argument("--headless")
self._browser = webdriver.Chrome(options=chrome_opt)
else:
self._browser = webdriver.Chrome()
示例10: __init__
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxOptions [as 别名]
def __init__(self, username, old_password):
self.url = "http://hetianlab.com/"
self.login_url = "http://hetianlab.com/loginLab.do"
self.username = username
self.old_password = old_password
self.new_password = (yield_new_password(), "******")[0]
self.options = webdriver.FirefoxOptions()
self.options.add_argument("-headless")
self.browser = webdriver.Firefox(options=self.options)
print("init ok")
示例11: driver_select
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxOptions [as 别名]
def driver_select(): #
'''
it configures what each browser should do
and gives the driver variable that is used
to perform any actions below this function.
'''
browser = get_browser_config()
data_dir = get_data_dir()
executable = get_browser_executable()
driver_binary = get_driver_binary()
binary = None if not driver_binary else driver_binary
if browser == 'firefox':
fireFoxOptions = webdriver.FirefoxOptions()
fireFoxOptions.headless = True
fireFoxOptions.add_argument('--log fatal')
if binary == None:
driver = webdriver.Firefox(options=fireFoxOptions, service_log_path=os.path.devnull)
else:
try:
driver = webdriver.Firefox(options=fireFoxOptions, service_log_path=os.path.devnull)
except:
driver = webdriver.Firefox(executable_path=binary, options=fireFoxOptions, service_log_path=os.path.devnull)
elif browser == 'chrome':
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
profile_path = os.path.join(data_dir, 'Selenium_chromium')
log_path = os.path.join(data_dir, 'chromedriver.log')
chrome_options.add_argument(f'--log-path {log_path}')
chrome_options.add_argument(f"--user-data-dir={profile_path}")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--window-size=1920,1080")
chrome_options.add_argument(f'user-agent={get_random_header()}')
if binary == None:
if executable == None:
driver = webdriver.Chrome(options=chrome_options)
else:
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
cap = DesiredCapabilities.CHROME
cap['binary_location'] = executable
driver = webdriver.Chrome(desired_capabilities=cap, options=chrome_options)
else:
if executable == None:
driver = webdriver.Chrome(options=chrome_options)
else:
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
cap = DesiredCapabilities.CHROME
cap['binary_location'] = executable
driver = webdriver.Chrome(executable_path=binary, desired_capabilities=cap, options=chrome_options)
return driver