Python selenium.webdriver.FirefoxOptions() Examples
The following are 11
code examples of selenium.webdriver.FirefoxOptions().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
selenium.webdriver
, or try the search function
.
Example #1
Source File: make.py From facebook-friends-map with MIT License | 13 votes |
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
Example #2
Source File: capabilities.py From nerodia with MIT License | 6 votes |
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
Example #3
Source File: __init__.py From selenium-python-helium with MIT License | 5 votes |
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)
Example #4
Source File: __init__.py From selenium-python-helium with MIT License | 5 votes |
def _get_firefox_options(self, headless, options): result = FirefoxOptions() if options is None else options if headless: result.headless = True return result
Example #5
Source File: testAllFirefox.py From -Automating-Web-Testing-with-Selenium-and-Python with MIT License | 5 votes |
def setUp(self): firefox_options = webdriver.FirefoxOptions() firefox_options.add_argument('headless') self.driver = webdriver.Firefox(options=firefox_options)
Example #6
Source File: testAll_firefox.py From -Automating-Web-Testing-with-Selenium-and-Python with MIT License | 5 votes |
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())
Example #7
Source File: test_ui.py From todoism with MIT License | 5 votes |
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.')
Example #8
Source File: selenium_test_case.py From iguana with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
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)
Example #9
Source File: openload_dl.py From openload_dl with MIT License | 5 votes |
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()
Example #10
Source File: fuckCTF.py From PythonCrawler with MIT License | 5 votes |
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")
Example #11
Source File: selescrape.py From anime-downloader with The Unlicense | 4 votes |
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