def get_firefox_driver(): firefox_path = '/usr/bin/firefox' firefox_options = Options() firefox_options.add_argument("--headless") firefox_options.add_argument("--window-size=%s" % WINDOW_SIZE) firefox_options.binary = firefox_path firefox_options.profile = webdriver.FirefoxProfile() return webdriver.Firefox( firefox_options=firefox_options, log_path="/tmp/geckodriver.log" )
def firefox_driver(self): options = Options() options.add_argument("--headless") binary = FirefoxBinary( 'C:/Program Files (x86)/Mozilla Firefox/firefox.exe') options.binary = binary fp = ( r'C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles\oqmqnsih.default' ) options.profile = fp cap = DesiredCapabilities().FIREFOX cap["marionette"] = False #driver = webdriver.Firefox(executable_path='E:/geckodriver-v0.26.0-win64/geckodriver.exe',capabilities=cap, options=chrome_options) driver = webdriver.Firefox( executable_path='E:/geckodriver-v0.26.0-win64/geckodriver.exe', firefox_options=options) print('got driver') return driver
def _process_firefox_options(self, opts): from selenium.webdriver.firefox.options import Options if isinstance(opts, Options): options = opts else: options = Options() if 'args' in opts: for arg in opts.pop('args'): options.add_argument(arg) 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['firefox_options'] = options
def getDriver( self, client="firefox", username="******", proxy=None, command_executor=None, loadstyles=False, profile = "/app/google-chrome/Profile", headless=False, autoconnect=True, logger=None, extra_params=None, chrome_options=None, # executable_path="/app/vendor/geckodriver/" executable_path=None ): """Initialises the webdriver""" print("((((((((((((((((()))))))))))))))))") print("((((((((((((((((()))))))))))))))))") print("((((((((((((((((()))))))))))))))))") print("((((((((((((((((()))))))))))))))))") print("((((((((((((((((()))))))))))))))))") print("((((((((((((((((())))))))))))))))) STATTING WEBDRIVER profile - ",profile) # self.logger = logger or self.logger extra_params = extra_params or {} if profile is not None: self._profile_path = profile self.logger.info("Checking for profile at %s" % self._profile_path) if not os.path.exists(self._profile_path): self.logger.critical("Could not find profile at %s" % profile) raise WhatsAPIException("Could not find profile at %s" % profile) else: self._profile_path = None self.client = client.lower() if self.client == "firefox": if self._profile_path is not None: self._profile = webdriver.FirefoxProfile(self._profile_path) else: self._profile = webdriver.FirefoxProfile() if not loadstyles: # Disable CSS self._profile.set_preference("permissions.default.stylesheet", 2) # Disable images self._profile.set_preference("permissions.default.image", 2) # Disable Flash self._profile.set_preference( "dom.ipc.plugins.enabled.libflashplayer.so", "false" ) if proxy is not None: self.set_proxy(proxy) options = Options() if headless: options.set_headless() options.profile = self._profile capabilities = DesiredCapabilities.FIREFOX.copy() capabilities["webStorageEnabled"] = True self.logger.info("Starting webdriver") if executable_path is not None: executable_path = os.path.abspath(executable_path) self.logger.info("Starting webdriver") self.driver = webdriver.Firefox( # firefox_binary=firefox_binary, capabilities=capabilities, options=options, executable_path=executable_path, **extra_params, ) else: self.logger.info("Starting webdriver") self.driver = webdriver.Firefox( # firefox_binary=firefox_binary, capabilities=capabilities, options=options, **extra_params ) elif self.client == "chrome": self._profile = webdriver.ChromeOptions() if self._profile_path is not None: self._profile.add_argument("user-data-dir=%s" % self._profile_path) if proxy is not None: self._profile.add_argument("--proxy-server=%s" % proxy) if headless: self._profile.add_argument("headless") if chrome_options is not None: self._profile = chrome_options ## for option in chrome_options: ## self._profile.add_argument(option) # self.logger.info("Starting webdriver") self.driver = webdriver.Chrome(executable_path=executable_path,chrome_options=self._profile, **extra_params) elif client == "remote": if self._profile_path is not None: self._profile = webdriver.FirefoxProfile(self._profile_path) else: self._profile = webdriver.FirefoxProfile() capabilities = DesiredCapabilities.FIREFOX.copy() self.driver = webdriver.Remote( command_executor=command_executor, desired_capabilities=capabilities, **extra_params, ) else: self.logger.error("Invalid client: %s" % client) # self.username = username # self.wapi_functions = WapiJsWrapper(self.driver, self) self.driver.set_script_timeout(500) self.driver.implicitly_wait(10) if autoconnect: self.connect()