예제 #1
0
    def __init__(self,
                 options=None,
                 capabilities=None,
                 service_url=None,
                 session_id=None):
        if options == None:
            self.service = False
        else:
            self.service = True
            self.address = options[0]
            self.who = options[1]
        # super(Chrome_Remote, self).__init__(port=port)
        if service_url is None and session_id is None:
            raise NameError

        if capabilities is None:
            capabilities = DesiredCapabilities.CHROME.copy()

        self.capabilities = dict(capabilities)

        self.w3c = True

        executor = ChromeRemoteConnection(remote_server_addr=service_url)
        self.session_id = session_id
        self.command_executor = executor
        self.command_executor.w3c = self.w3c
        if type(self.command_executor) is bytes or isinstance(
                self.command_executor, str):
            self.command_executor = RemoteConnection(self.command_executor,
                                                     keep_alive=True)
        self._is_remote = True
        self.error_handler = ErrorHandler()
        self._switch_to = SwitchTo(self)
        self._mobile = Mobile(self)
        self.file_detector = LocalFileDetector()
예제 #2
0
    def __init__(self, service_url="http://localhost:9515",options=None,desired_capabilities=None, chrome_options=None, keep_alive=True,debug=False,logger_name=None):

        if chrome_options:
            warnings.warn('use options instead of chrome_options',
                          DeprecationWarning, stacklevel=2)
            options = chrome_options

        if options is None:
            # desired_capabilities stays as passed in
            if desired_capabilities is None:
                desired_capabilities = self.create_options().to_capabilities()
        else:
            if desired_capabilities is None:
                desired_capabilities = options.to_capabilities()
            else:
                desired_capabilities.update(options.to_capabilities())

        try:
            self.remote= RemoteWebDriver.__init__(
                self,command_executor=ChromeRemoteConnection(
                    remote_server_addr=service_url,
                    keep_alive=keep_alive,
                    debug=debug,
                    logger_name=logger_name),
                    desired_capabilities=desired_capabilities)
        except Exception:
            self.quit()
            raise
예제 #3
0
    def __init__(self, executable_path="chromedriver", port=0, use_mobile_emulation=False,
                 options=None, service_args=None,
                 desired_capabilities=None, service_log_path=None,
                 chrome_options=None):
        self.use_mobile_emulation = use_mobile_emulation

        """
           Creates a new instance of the violent chrome driver.

           Starts the service and then creates new instance of chrome driver.

           :Args:
            - executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH
            - port - port you would like the service to run, if left as 0, a free port will be found.
            - desired_capabilities: Dictionary object with non-browser specific
              capabilities only, such as "proxy" or "loggingPref".
            - options: this takes an instance of ChromeOptions
            - use_mobile_emulation: whether use mobile emulation or not , default is False
        """

        if self.use_mobile_emulation:
            mobile_emulation = {
                "deviceMetrics": {"width": 360, "height": 640, "pixelRatio": 3.0},
                "userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19"}
            chrome_options = Options()
            chrome_options.add_argument('disable-infobars')
            chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)

        if chrome_options:
            warnings.warn('use options instead of chrome_options', DeprecationWarning)
            options = chrome_options

        if options is None:
            # desired_capabilities stays as passed in
            if desired_capabilities is None:
                desired_capabilities = self.create_options().to_capabilities()
        else:
            if desired_capabilities is None:
                desired_capabilities = options.to_capabilities()
            else:
                desired_capabilities.update(options.to_capabilities())

        self.service = Service(
            executable_path,
            port=port,
            service_args=service_args,
            log_path=service_log_path)
        self.service.start()

        try:
            RemoteWebDriver.__init__(
                self,
                command_executor=ChromeRemoteConnection(
                    remote_server_addr=self.service.service_url),
                desired_capabilities=desired_capabilities)
        except Exception:
            self.quit()
            raise
        self._is_remote = False
예제 #4
0
    def __init__(self,
                 executable_path="chromedriver",
                 port=0,
                 options=None,
                 service_args=None,
                 desired_capabilities=None,
                 service_log_path=None,
                 chrome_options=None,
                 keep_alive=True):
        """
        Creates a new instance of the chrome driver.

        Starts the service and then creates new instance of chrome driver.

        :Args:
         - executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH
         - port - port you would like the service to run, if left as 0, a free port will be found.
         - options - this takes an instance of ChromeOptions
         - service_args - List of args to pass to the driver service
         - desired_capabilities - Dictionary object with non-browser specific
           capabilities only, such as "proxy" or "loggingPref".
         - service_log_path - Where to log information from the driver.
         - chrome_options - Deprecated argument for options
         - keep_alive - Whether to configure ChromeRemoteConnection to use HTTP keep-alive.
        """
        if chrome_options:
            warnings.warn('use options instead of chrome_options',
                          DeprecationWarning,
                          stacklevel=2)
            options = chrome_options

        if options is None:
            # desired_capabilities stays as passed in
            if desired_capabilities is None:
                desired_capabilities = self.create_options().to_capabilities()
        else:
            if desired_capabilities is None:
                desired_capabilities = options.to_capabilities()
            else:
                desired_capabilities.update(options.to_capabilities())

        self.service = Service(executable_path,
                               port=port,
                               service_args=service_args,
                               log_path=service_log_path)
        self.service.start()

        try:
            WebDriver.__init__(self,
                               command_executor=ChromeRemoteConnection(
                                   remote_server_addr=self.service.service_url,
                                   keep_alive=keep_alive),
                               desired_capabilities=desired_capabilities)
        except Exception:
            self.quit()
            raise
        self._is_remote = False
예제 #5
0
    def __init__(self,
                 executable_path="chromedriver",
                 port=0,
                 options=None,
                 service_args=None,
                 desired_capabilities=None,
                 service_log_path=None,
                 chrome_options=None):
        """
        Creates a new instance of the chrome driver.

        Starts the service and then creates new instance of chrome driver.

        :Args:
         - executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH
         - port - port you would like the service to run, if left as 0, a free port will be found.
         - desired_capabilities: Dictionary object with non-browser specific
           capabilities only, such as "proxy" or "loggingPref".
         - options: this takes an instance of ChromeOptions
        """
        if chrome_options:
            warnings.warn('use options instead of chrome_options',
                          DeprecationWarning)
            options = chrome_options

        if options is None:
            # desired_capabilities stays as passed in
            if desired_capabilities is None:
                desired_capabilities = self.create_options().to_capabilities()
        else:
            if desired_capabilities is None:
                desired_capabilities = options.to_capabilities()
            else:
                desired_capabilities.update(options.to_capabilities())

        self.service = myService(executable_path,
                                 port=port,
                                 service_args=service_args,
                                 log_path=service_log_path)
        self.service.start()

        try:
            RemoteWebDriver.__init__(
                self,
                command_executor=ChromeRemoteConnection(
                    remote_server_addr=self.service.service_url),
                desired_capabilities=desired_capabilities)
        except Exception:
            self.quit()
            raise
        self._is_remote = False
예제 #6
0
파일: chrome.py 프로젝트: schipiga/dilium
    def launch(self):
        """Launch chrome browser."""
        self._node.start_webdriver()

        executor = ChromeRemoteConnection(
            remote_server_addr=self._node.webdriver_url)

        try:
            super(webdriver.Chrome, self).__init__(
                command_executor=executor,
                desired_capabilities=self._desired_capabilities)
        except:
            self._node.stop_webdriver()
            raise
예제 #7
0
    def __init__(self, capabilities=None, service_url=None, session_id=None):
        if service_url is None and session_id is None:
            raise NameError

        if capabilities is None:
            capabilities = DesiredCapabilities.FIREFOX.copy()

        self.capabilities = dict(capabilities)
        self.w3c = True
        executor = ChromeRemoteConnection(remote_server_addr=service_url)
        self.session_id = session_id
        self.command_executor = executor
        self.command_executor.w3c = self.w3c
        if type(self.command_executor) is bytes or isinstance(self.command_executor, str):
            self.command_executor = RemoteConnection(self.command_executor, keep_alive=True)
        self._is_remote = True
        self.error_handler = ErrorHandler()
        self._switch_to = SwitchTo(self)
        self._mobile = Mobile(self)
        self.file_detector = LocalFileDetector()
예제 #8
0
import dataflows as DF
import time
import logging
import csv

from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.remote_connection import ChromeRemoteConnection
ChromeRemoteConnection.set_timeout(300)

from datapackage_pipelines_budgetkey.common.google_chrome import google_chrome_driver


def wrapper(year):
    gcd = None
    try:
        gcd = google_chrome_driver(initial='http://example.com/')
        return scraper(gcd, year)
    finally:
        logging.info('Tearing down %r', gcd)
        if gcd:
            gcd.teardown()


def get_chart(driver, charts_wh):
    # Switch to results page & iframe
    driver.switch_to.window(charts_wh)
    frame = WebDriverWait(driver, 30).until(
        EC.presence_of_element_located((By.ID, "openDocChildFrame"))