Exemple #1
0
    def _create_driver(self):
        browsers = webdriver.DRIVER_PREFERENCE[platform.system()]
        for browser in browsers:
            kwargs = {}
            if self._headless:
                from selenium.webdriver import ChromeOptions

                chrome_options = ChromeOptions()
                chrome_options.add_argument("--no-sandbox")
                chrome_options.add_argument("--window-size=1280,1024")
                chrome_options.add_argument("--disable-dev-shm-usage")
                chrome_options.headless = True

                kwargs["options"] = chrome_options
            for download in [False, True]:
                executable = webdriver.executable(browser, download=download)
                try:
                    if executable:
                        driver = webdriver.start(browser,
                                                 executable_path=executable,
                                                 **kwargs)
                    else:
                        driver = webdriver.start(browser, **kwargs)
                    return driver, browser
                except WebDriverException:
                    if self.logger.level >= logging.DEBUG:
                        self.logger.exception(
                            "Error trying to start with executable: %s",
                            executable)

        raise ValueError("No valid browser found")
Exemple #2
0
    def create_rpa_webdriver(self,
                             browser: str,
                             options: dict,
                             download: bool = False) -> Any:
        """Create a webdriver instance for the given browser.

        The driver will be downloaded if it does not exist when ``download`` is True.

        ``browser`` name of the browser

        ``options`` options for webdriver

        ``download`` if the driver should be download, default ``False``

        Returns an index of the webdriver session, ``None`` if webdriver
        was not initialized.
        """
        self.logger.debug("Driver options for create_rpa_webdriver: %s",
                          options)
        executable = webdriver.executable(browser, download)

        try:
            browser = browser.lower().capitalize()
            browser_management = BrowserManagementKeywords(self)
            if executable:
                index = browser_management.create_webdriver(
                    browser, **options, executable_path=executable)
            else:
                index = browser_management.create_webdriver(browser, **options)

            return index
        except WebDriverException as err:
            self.logger.info("Could not open driver: %s", err)

        return None
Exemple #3
0
    def _create_webdriver(self, browser, alias, download, **kwargs):
        """Create a webdriver instance for the given browser.

        Returns an index/alias of the webdriver session,
        or ``None`` if a webdriver was not initialized.
        """
        executable = webdriver.executable(browser, download)
        if executable:
            kwargs.setdefault("executable_path", executable)

        library = BrowserManagementKeywords(self)
        browser = browser.lower().capitalize()

        return library.create_webdriver(browser, alias, **kwargs)