Example #1
0
    def __init__(self,
                 user_agent=None,
                 wait_time=2,
                 fullscreen=False,
                 persistent_session=False,
                 **kwargs):
        options = Options()

        if user_agent is not None:
            options.add_argument("--user-agent=" + user_agent)

        if fullscreen:
            options.add_argument('--kiosk')

        options.add_argument('-F')
        options.add_argument('--args')
        options.add_argument('--disable-web-security')
        if persistent_session:
            options.add_argument(
                '--user-data-dir=/tmp/temp_chrome_user_data_dir_for_cordova_browser'
            )
        else:
            options.add_argument('--incognito')

        dc = DesiredCapabilities.CHROME
        dc['loggingPrefs'] = {'browser': 'ALL'}

        self.driver = Chrome(chrome_options=options,
                             desired_capabilities=dc,
                             **kwargs)
        self.element_class = WebDriverElement

        self._cookie_manager = CookieManager(self.driver)

        super(WebDriver, self).__init__(wait_time)
Example #2
0
    def __init__(self,
                 profile=None,
                 extensions=None,
                 user_agent=None,
                 profile_preferences=None):
        self.old_popen = subprocess.Popen
        firefox_profile = FirefoxProfile(profile)
        firefox_profile.set_preference('extensions.logging.enabled', False)
        firefox_profile.set_preference('network.dns.disableIPv6', False)

        if user_agent is not None:
            firefox_profile.set_preference('general.useragent.override',
                                           user_agent)

        if profile_preferences:
            for key, value in profile_preferences.iteritems():
                firefox_profile.set_preference(key, value)

        if extensions:
            for extension in extensions:
                firefox_profile.add_extension(extension)

        self._patch_subprocess()
        self.driver = Firefox(firefox_profile)
        self._unpatch_subprocess()

        self.element_class = WebDriverElement

        self._cookie_manager = CookieManager(self.driver)

        super(WebDriver, self).__init__()
Example #3
0
    def __init__(self,
                 user_agent=None,
                 wait_time=2,
                 fullscreen=False,
                 **kwargs):

        options = Options()

        if user_agent is not None:
            options.add_argument("--user-agent=" + user_agent)

        if fullscreen:
            options.add_argument('--kiosk')

        prefs = {
            "download": {
                "default_directory": _DOWNLOAD_PATH,
                "directory_upgrade": True,
                "extensions_to_open": ""
            }
        }

        options.add_experimental_option("prefs", prefs)

        self.driver = Chrome(chrome_options=options, **kwargs)

        self.element_class = WebDriverElement

        self._cookie_manager = CookieManager(self.driver)

        super(WebDriver, self).__init__(wait_time)
Example #4
0
    def __init__(self,
                 options=None,
                 user_agent=None,
                 wait_time=2,
                 fullscreen=False,
                 incognito=False,
                 headless=False,
                 **kwargs):

        options = Options() if options is None else options

        if user_agent is not None:
            options.add_argument("--user-agent=" + user_agent)

        if incognito:
            options.add_argument("--incognito")

        if fullscreen:
            options.add_argument('--kiosk')

        if headless:
            options.add_argument('--headless')
            options.add_argument('--disable-gpu')

        self.driver = Chrome(chrome_options=options, **kwargs)

        self.element_class = WebDriverElement

        self._cookie_manager = CookieManager(self.driver)

        super(WebDriver, self).__init__(wait_time)
Example #5
0
    def __init__(self,
                 profile=None,
                 extensions=None,
                 user_agent=None,
                 profile_preferences=None,
                 fullscreen=False,
                 wait_time=2):

        firefox_profile = FirefoxProfile(profile)
        firefox_profile.set_preference('extensions.logging.enabled', False)
        firefox_profile.set_preference('network.dns.disableIPv6', False)

        if user_agent is not None:
            firefox_profile.set_preference('general.useragent.override',
                                           user_agent)

        if profile_preferences:
            for key, value in profile_preferences.items():
                firefox_profile.set_preference(key, value)

        if extensions:
            for extension in extensions:
                firefox_profile.add_extension(extension)

        self.driver = Firefox(firefox_profile)

        if fullscreen:
            ActionChains(self.driver).send_keys(Keys.F11).perform()

        self.element_class = WebDriverElement

        self._cookie_manager = CookieManager(self.driver)

        super(WebDriver, self).__init__(wait_time)
Example #6
0
    def __init__(
        self,
        browser="firefox",
        wait_time=2,
        command_executor=DEFAULT_URL,
        **kwargs
    ):
        browser_name = browser.upper()
        # Handle case where user specifies IE with a space in it
        if browser_name == "INTERNET EXPLORER":
            browser_name = "INTERNETEXPLORER"

        # If no desired capabilities specified, add default ones
        caps = getattr(DesiredCapabilities, browser_name, {})
        if kwargs.get('desired_capabilities'):
            # Combine user's desired capabilities with default
            caps.update(kwargs['desired_capabilities'])

        kwargs['desired_capabilities'] = caps

        self.driver = Remote(command_executor, **kwargs)

        self.element_class = WebDriverElement

        self._cookie_manager = CookieManager(self.driver)

        super(WebDriver, self).__init__(wait_time)
Example #7
0
    def __init__(self,
                 profile=None,
                 extensions=None,
                 user_agent=None,
                 profile_preferences=None,
                 fullscreen=False,
                 wait_time=2,
                 timeout=90,
                 capabilities=None,
                 headless=False,
                 incognito=False,
                 **kwargs):

        firefox_profile = FirefoxProfile(profile)
        firefox_profile.set_preference("extensions.logging.enabled", False)
        firefox_profile.set_preference("network.dns.disableIPv6", False)

        firefox_capabilities = DesiredCapabilities().FIREFOX
        firefox_capabilities["marionette"] = True

        firefox_options = Options()

        if capabilities:
            for key, value in capabilities.items():
                firefox_capabilities[key] = value

        if user_agent is not None:
            firefox_profile.set_preference("general.useragent.override",
                                           user_agent)

        if profile_preferences:
            for key, value in profile_preferences.items():
                firefox_profile.set_preference(key, value)

        if extensions:
            for extension in extensions:
                firefox_profile.add_extension(extension)

        if headless:
            firefox_options.add_argument("--headless")

        if incognito:
            firefox_options.add_argument("-private")

        self.driver = Firefox(firefox_profile,
                              capabilities=firefox_capabilities,
                              options=firefox_options,
                              timeout=timeout,
                              **kwargs)

        if fullscreen:
            self.driver.fullscreen_window()

        self.element_class = WebDriverElement

        self._cookie_manager = CookieManager(self.driver)

        super(WebDriver, self).__init__(wait_time)
Example #8
0
    def __init__(self, full_screen=False, wait_time=2, **ability_args):

        self.driver = SafariDriver()

        self.element_class = SafariDriverElement

        self._cookie_manager = CookieManager(self.driver)

        super(Safari, self).__init__(wait_time)
Example #9
0
    def __init__(self, driver=None, wait_time=2):
        self.wait_time = wait_time

        self.links = FindLinks(self)

        self.driver = driver

        self.element_class = WebDriverElement

        self._cookie_manager = CookieManager(self.driver)
Example #10
0
    def __init__(self):
        self._patch_subprocess()
        self.driver = Chrome()
        self._unpatch_subprocess()

        self.element_class = WebDriverElement

        self._cookie_manager = CookieManager(self.driver)

        super(WebDriver, self).__init__()
Example #11
0
    def __init__(self,
                 profile=None,
                 extensions=None,
                 user_agent=None,
                 profile_preferences=None,
                 fullscreen=False,
                 wait_time=2,
                 timeout=90,
                 capabilities=None,
                 headless=False,
                 **kwargs):

        firefox_profile = FirefoxProfile(profile)
        firefox_profile.set_preference('extensions.logging.enabled', False)
        firefox_profile.set_preference('network.dns.disableIPv6', False)

        firefox_capabilities = DesiredCapabilities().FIREFOX
        firefox_capabilities["marionette"] = True

        if capabilities:
            for key, value in capabilities.items():
                firefox_capabilities[key] = value

        if user_agent is not None:
            firefox_profile.set_preference('general.useragent.override',
                                           user_agent)

        if profile_preferences:
            for key, value in profile_preferences.items():
                firefox_profile.set_preference(key, value)

        if extensions:
            for extension in extensions:
                firefox_profile.add_extension(extension)

        if headless:
            os.environ.update({"MOZ_HEADLESS": '1'})
            binary = FirefoxBinary()
            binary.add_command_line_options('-headless')
            kwargs['firefox_binary'] = binary

        self.driver = Firefox(firefox_profile,
                              capabilities=firefox_capabilities,
                              timeout=timeout,
                              **kwargs)

        if fullscreen:
            ActionChains(self.driver).send_keys(Keys.F11).perform()

        self.element_class = WebDriverElement

        self._cookie_manager = CookieManager(self.driver)

        super(WebDriver, self).__init__(wait_time)
Example #12
0
    def __init__(self):
        firefox_profile = FirefoxProfile()
        firefox_profile.set_preference('extensions.logging.enabled', 'false')

        self._patch_subprocess()
        self.driver = Firefox(firefox_profile)
        self._unpatch_subprocess()

        self.element_class = WebDriverElement

        self._cookie_manager = CookieManager(self.driver)

        super(WebDriver, self).__init__()
Example #13
0
    def __init__(self, user_agent=None, wait_time=2, **kwargs):
        options = Options()

        if user_agent is not None:
            options.add_argument("--user-agent=" + user_agent)

        self.driver = Chrome(chrome_options=options, **kwargs)

        self.element_class = WebDriverElement

        self._cookie_manager = CookieManager(self.driver)

        super(WebDriver, self).__init__(wait_time)
Example #14
0
    def __init__(self, wait_time=2, fullscreen=False, binary=""):

        dc = {}
        dc["browserName"] = "electron"
        dc["chromeOptions"] = {
            "binary": binary,
        }
        self.driver = Chrome(desired_capabilities=dc)
        self.element_class = WebDriverElement

        self._cookie_manager = CookieManager(self.driver)

        super(ElectronWebDriver, self).__init__(wait_time)
Example #15
0
    def __init__(self, url=DEFAULT_URL, browser='firefox', wait_time=2, **ability_args):
        browsername = browser.upper()
        # Handle case where user specifies IE with a space in it
        if browsername == 'INTERNET EXPLORER':
            browsername = 'INTERNETEXPLORER'
        abilities = getattr(DesiredCapabilities, browsername, {})
        abilities.update(ability_args)
        self.driver = Remote(url, abilities)

        self.element_class = WebDriverElement

        self._cookie_manager = CookieManager(self.driver)

        super(WebDriver, self).__init__(wait_time)
Example #16
0
    def __init__(self,
                 wait_time=2,
                 fullscreen=False,
                 binary=''):

        dc = {}
        dc['browserName'] = 'electron'
        dc['chromeOptions'] = {
            'binary': binary,
        }
        self.driver = Chrome(desired_capabilities=dc)
        self.element_class = WebDriverElement

        self._cookie_manager = CookieManager(self.driver)

        super(ElectronWebDriver, self).__init__(wait_time)
Example #17
0
    def __init__(
        self,
        user_agent=None,
        wait_time=2,
        fullscreen=False,
        options=None,
        headless=False,
        desired_capabilities=None,
        **kwargs,
    ):

        options = Options() if options is None else options

        if user_agent is not None:
            options.add_argument("--user-agent=" + user_agent)

        options.add_argument("--use-fake-device-for-media-stream")
        options.add_argument("--use-fake-ui-for-media-stream")
        if fullscreen:
            options.add_argument("--kiosk")

        if headless:
            # noinspection PyDeprecation
            # windows: chrome version >= 60
            options.set_headless()

        prefs = {
            "download": {
                "default_directory": _DOWNLOAD_PATH,
                "directory_upgrade": True,
                "extensions_to_open": "",
            }
        }

        options.add_experimental_option("prefs", prefs)

        chrome_capabilities = DesiredCapabilities().CHROME.copy()
        if desired_capabilities:
            chrome_capabilities.update(desired_capabilities)

        self.driver = Chrome(chrome_options=options,
                             desired_capabilities=chrome_capabilities,
                             **kwargs)
        self.element_class = WebDriverElement
        self._cookie_manager = CookieManager(self.driver)

        super(WebDriver, self).__init__(wait_time)
Example #18
0
    def __init__(self,
                 profile=None,
                 extensions=None,
                 user_agent=None,
                 profile_preferences=None,
                 fullscreen=False,
                 wait_time=2):

        firefox_profile = FirefoxProfile(profile)
        firefox_profile.set_preference('extensions.logging.enabled', False)
        firefox_profile.set_preference('network.dns.disableIPv6', False)

        firefox_profile.set_preference("browser.download.folderList", 2)
        firefox_profile.set_preference(
            "browser.download.manager.showWhenStarting", False)
        firefox_profile.set_preference("browser.download.dir", _DOWNLOAD_PATH)
        firefox_profile.set_preference(
            "browser.helperApps.neverAsk.saveToDisk", _ALL_MIME_TYPES)
        firefox_profile.set_preference("permissions.default.microphone", 1)
        firefox_profile.set_preference("permissions.default.camera", 1)
        # firefox_profile.set_preference("browser.helperApps.alwaysAsk.force", False)
        # firefox_profile.set_preference("browser.download.manager.showWhenStarting", False)

        if user_agent is not None:
            firefox_profile.set_preference('general.useragent.override',
                                           user_agent)

        if profile_preferences:
            for key, value in profile_preferences.items():
                firefox_profile.set_preference(key, value)

        if extensions:
            for extension in extensions:
                firefox_profile.add_extension(extension)

        self.driver = Firefox(firefox_profile)

        if fullscreen:
            ActionChains(self.driver).send_keys(Keys.F11).perform()

        self.element_class = WebDriverElement

        self._cookie_manager = CookieManager(self.driver)

        super(WebDriver, self).__init__(wait_time)
Example #19
0
    def __init__(self,
                 user_agent=None,
                 load_images=True,
                 desired_capabilities=None,
                 wait_time=2,
                 **kwargs):
        capabilities = DesiredCapabilities.PHANTOMJS.copy()
        if user_agent is not None:
            capabilities['phantomjs.page.settings.userAgent'] = user_agent
        capabilities['phantomjs.page.settings.loadImages'] = load_images
        if desired_capabilities:
            capabilities.update(desired_capabilities)

        self.driver = PhantomJS(desired_capabilities=capabilities, **kwargs)

        self._cookie_manager = CookieManager(self.driver)

        super(WebDriver, self).__init__(wait_time)
    def __init__(self, user_agent=None, load_images=True,
                 desired_capabilities=None, wait_time=2,
                 custom_headers={}, **kwargs):
        capabilities = DesiredCapabilities.PHANTOMJS.copy()
        if user_agent is not None:
            capabilities['phantomjs.page.settings.userAgent'] = user_agent
        capabilities['phantomjs.page.settings.loadImages'] = load_images
        if isinstance(custom_headers, dict):
            for name, value in custom_headers.items():
                capabilities['phantomjs.page.customHeaders.%s' % name] = value
        if desired_capabilities:
            capabilities.update(desired_capabilities)

        self.driver = PhantomJS(desired_capabilities=capabilities, **kwargs)

        self._cookie_manager = CookieManager(self.driver)

        super(WebDriver, self).__init__(wait_time)
Example #21
0
    def __init__(self, profile=None, extensions=None):
        self.old_popen = subprocess.Popen
        firefox_profile = FirefoxProfile(profile)
        firefox_profile.set_preference('extensions.logging.enabled', False)
        firefox_profile.set_preference('network.dns.disableIPv6', False)

        if extensions:
            for extension in extensions:
                firefox_profile.add_extension(extension)

        self._patch_subprocess()
        self.driver = Firefox(firefox_profile)
        self._unpatch_subprocess()

        self.element_class = WebDriverElement

        self._cookie_manager = CookieManager(self.driver)

        super(WebDriver, self).__init__()
Example #22
0
    def __init__(self, profile=None, extensions=None, user_agent=None,
                 profile_preferences=None, fullscreen=False, wait_time=2,
                 timeout=90, capabilities=None, log_path=None):

        firefox_profile = FirefoxProfile(profile)
        firefox_profile.set_preference('extensions.logging.enabled', False)
        firefox_profile.set_preference('network.dns.disableIPv6', False)

        firefox_capabilities = DesiredCapabilities().FIREFOX
        firefox_capabilities["marionette"] = True

        if capabilities:
            for key, value in capabilities.items():
                firefox_capabilities[key] = value

        if user_agent is not None:
            firefox_profile.set_preference(
                'general.useragent.override', user_agent)

        if profile_preferences:
            for key, value in profile_preferences.items():
                firefox_profile.set_preference(key, value)

        if extensions:
            for extension in extensions:
                firefox_profile.add_extension(extension)

        log_path = log_path if log_path is not None else os.devnull
        self.driver = Firefox(firefox_profile,
                              capabilities=firefox_capabilities,
                              timeout=timeout,
                              log_path=log_path)

        if fullscreen:
            ActionChains(self.driver).send_keys(Keys.F11).perform()

        self.element_class = WebDriverElement

        self._cookie_manager = CookieManager(self.driver)

        super(WebDriver, self).__init__(wait_time)
Example #23
0
 def __init__(self, profile=None, extensions=None, user_agent=None,
              profile_preferences=None, wait_time=2, firefox_path=None):
     firefox_profile = FirefoxProfile(profile)
     firefox_profile.set_preference('extensions.logging.enabled', False)
     firefox_profile.set_preference('network.dns.disableIPv6', False)
     if user_agent is not None:
         firefox_profile.set_preference('general.useragent.override',
                                        user_agent)
     if profile_preferences:
         for key, value in profile_preferences.items():
             firefox_profile.set_preference(key, value)
     if extensions:
         for extension in extensions:
             firefox_profile.add_extension(extension)
     if firefox_path:
         firefox_binary = FirefoxBinary(firefox_path=firefox_path)
         self.driver = Firefox(firefox_profile=firefox_profile,
                               firefox_binary=firefox_binary)
     else:
         self.driver = Firefox(firefox_profile)
     self.element_class = WebDriverElement
     self._cookie_manager = CookieManager(self.driver)
     super(WebDriver, self).__init__(wait_time)
Example #24
0
 def __init__(self, browser, wait_time=2):
     self.driver = browser
     self.element_class = WebDriverElement
     self._cookie_manager = CookieManager(self.driver)
     super(WebDriver, self).__init__(wait_time)
Example #25
0
    def __init__(
        self,
        profile=None,
        extensions=None,
        user_agent=None,
        profile_preferences=None,
        fullscreen=False,
        wait_time=2,
        timeout=90,
        capabilities=None,
        headless=False,
        incognito=False,
        **kwargs
    ):

        firefox_profile = FirefoxProfile(profile)
        firefox_profile.set_preference("extensions.logging.enabled", False)
        firefox_profile.set_preference("network.dns.disableIPv6", False)

        firefox_capabilities = DesiredCapabilities().FIREFOX
        firefox_capabilities["marionette"] = True

        firefox_options = Options()

        if capabilities:
            for key, value in capabilities.items():
                firefox_capabilities[key] = value

        if user_agent is not None:
            firefox_profile.set_preference("general.useragent.override", user_agent)

        if profile_preferences:
            for key, value in profile_preferences.items():
                firefox_profile.set_preference(key, value)

        if extensions:
            for extension in extensions:
                firefox_profile.add_extension(extension)

        if headless:
            os.environ.update({"MOZ_HEADLESS": "1"})
            if 'firefox_binary' in kwargs:
                if isinstance(kwargs['firefox_binary'], six.string_types):
                    binary = FirefoxBinary(kwargs['firefox_binary'])
                else:
                    binary = kwargs['firefox_binary']
            else:
                binary = FirefoxBinary()
            binary.add_command_line_options("-headless")
            kwargs["firefox_binary"] = binary

        if incognito:
            firefox_options.add_argument("-private")

        self.driver = Firefox(
            firefox_profile,
            capabilities=firefox_capabilities,
            options=firefox_options,
            timeout=timeout,
            **kwargs
        )

        if fullscreen:
            ActionChains(self.driver).send_keys(Keys.F11).perform()

        self.element_class = WebDriverElement

        self._cookie_manager = CookieManager(self.driver)

        super(WebDriver, self).__init__(wait_time)
Example #26
0
    def __init__(
        self,
        profile=None,
        extensions=None,
        user_agent=None,
        profile_preferences=None,
        fullscreen=False,
        options=None,
        headless=False,
        wait_time=2,
        desired_capabilities=None,
    ):

        firefox_profile = FirefoxProfile(profile)
        firefox_profile.set_preference("extensions.logging.enabled", False)
        firefox_profile.set_preference("network.dns.disableIPv6", False)

        firefox_profile.set_preference("browser.download.folderList", 2)
        firefox_profile.set_preference(
            "browser.download.manager.showWhenStarting", False)
        firefox_profile.set_preference("browser.download.dir", _DOWNLOAD_PATH)
        firefox_profile.set_preference(
            "browser.helperApps.neverAsk.saveToDisk", _ALL_MIME_TYPES)
        firefox_profile.set_preference("permissions.default.microphone", 1)
        firefox_profile.set_preference("permissions.default.camera", 1)
        # firefox_profile.set_preference("browser.helperApps.alwaysAsk.force", False)
        # firefox_profile.set_preference("browser.download.manager.showWhenStarting", False)

        if user_agent is not None:
            firefox_profile.set_preference("general.useragent.override",
                                           user_agent)

        if profile_preferences:
            for key, value in profile_preferences.items():
                firefox_profile.set_preference(key, value)

        if extensions:
            for extension in extensions:
                firefox_profile.add_extension(extension)

        options = Options() if options is None else options

        if headless:
            # noinspection PyDeprecation
            options.set_headless()

        firefox_capabilities = DesiredCapabilities().FIREFOX.copy()
        firefox_capabilities["marionette"] = True
        if desired_capabilities:
            firefox_capabilities.update(desired_capabilities)

        self.driver = Firefox(firefox_profile,
                              capabilities=firefox_capabilities,
                              firefox_options=options)

        if fullscreen:
            ActionChains(self.driver).send_keys(Keys.F11).perform()

        self.element_class = WebDriverElement

        self._cookie_manager = CookieManager(self.driver)

        super(WebDriver, self).__init__(wait_time)