예제 #1
0
    def launch(self):
        #custom useragent for fetching mobile version of facebook
        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"

        # set options for mobile view
        options = Options()
        options.set_capability("deviceName", "iPhone")
        options.set_preference("general.useragent.override",
                               userAgent)
        # open window only for debugging
        if self.headless:
            self.msg("headless mode")
            options.add_argument('-headless')

        # launch the browser
        #TODO: Add support for other browsers
        self.driver = Firefox(
            executable_path=self.driverPath,
            options=options)
        self.wait = WebDriverWait(self.driver, timeout=100)
        self.msg("initiated")
        self.driver.get(self.url)
        self.msg("opening site "+str(self.url))
예제 #2
0
def get_firefox():
    binary = FirefoxBinary('/usr/bin/firefox')
    fp = webdriver.FirefoxProfile()
    fp.DEFAULT_PREFERENCES['frozen']['javascript.options.shared_memory'] = True
    fp.DEFAULT_PREFERENCES['frozen'][
        'javascript.options.wasm_baselinejit'] = False
    fp.DEFAULT_PREFERENCES['frozen']['javascript.options.wasm'] = True
    fp.DEFAULT_PREFERENCES['frozen']['javascript.options.wasm_ionjit'] = True
    fp.DEFAULT_PREFERENCES['frozen']['browser.tabs.remote.autostart'] = False
    fp.DEFAULT_PREFERENCES['frozen']['devtools.console.stdout.content'] = True
    options = FFOptions()
    fp.set_preference("browser.download.folderList", 2)
    fp.set_preference("browser.download.dir", "/mnt/homes/abhinav/Downloads")
    fp.set_preference("browser.download.useDownloadDir", True)
    fp.set_preference("browser.helperApps.neverAsk.saveToDisk",
                      "application/x-tar")
    fp.add_extension('webconsoletap-1.0-fx.xpi')
    options.profile = fp
    options.binary = '/usr/bin/firefox'
    options.add_argument('-contentproc=2')
    d = DesiredCapabilities.FIREFOX
    d['loggingPrefs'] = {'browser': 'ALL'}
    options.set_capability(name='loggingPrefs', value={'browser': 'ALL'})
    return webdriver.Firefox(executable_path='/usr/bin/geckodriver',
                             firefox_options=options,
                             capabilities=d)
예제 #3
0
    def get_firefox_options(self):
        opts = FirefoxOptions()

        if self.browser_binary:
            opts.binary_location = self.browser_binary

        #opts.log.level = "trace"

        opts.set_capability("acceptInsecureCerts", False)
        opts.set_capability("unhandledPromptBehavior", "ignore")

        opts.set_preference('extensions.webextensions.uuids',
                            f'{{"{FF_EXT_ID}": "{FF_UUID}"}}')

        opts.set_preference("dom.webdriver.enabled", False)

        # disable prefetching
        opts.set_preference("network.dns.disablePrefetch", True)
        opts.set_preference("network.prefetch-next", False)
        # disable OpenH264 codec downloading
        opts.set_preference("media.gmp-gmpopenh264.enabled", False)
        opts.set_preference("media.gmp-manager.url", "")
        # disable health reports
        opts.set_preference("datareporting.healthreport.service.enabled",
                            False)
        opts.set_preference("datareporting.healthreport.uploadEnabled", False)
        opts.set_preference("datareporting.policy.dataSubmissionEnabled",
                            False)
        # disable experiments
        opts.set_preference("experiments.enabled", False)
        opts.set_preference("experiments.supported", False)
        opts.set_preference("experiments.manifest.uri", "")
        # disable telemetry
        opts.set_preference("toolkit.telemetry.enabled", False)
        opts.set_preference("toolkit.telemetry.unified", False)
        opts.set_preference("toolkit.telemetry.archive.enabled", False)

        if self.firefox_tracking_protection == "off":
            # disable all content blocking/Tracking Protection features
            # https://wiki.mozilla.org/Security/Tracking_protection
            opts.set_preference("privacy.trackingprotection.enabled", False)
            opts.set_preference("privacy.trackingprotection.pbmode.enabled",
                                False)
            opts.set_preference(
                "privacy.trackingprotection.cryptomining.enabled", False)
            opts.set_preference(
                "privacy.trackingprotection.fingerprinting.enabled", False)
            opts.set_preference(
                "privacy.trackingprotection.socialtracking.enabled", False)
            # always allow third-party cookies
            opts.set_preference("network.cookie.cookieBehavior", 0)
        elif self.firefox_tracking_protection == "strict":
            opts.set_preference("browser.contentblocking.category", "strict")

        return opts
예제 #4
0
def get_firefox_web_driver():
    options = FOptions()
    options.set_capability('goog:loggingPrefs', {'performance': 'ALL'})
    options.add_argument("--disable-infobars")
    options.add_argument("--disable-notifications")
    profile = FirefoxProfile()
    profile.accept_untrusted_certs = True
    LOGGER.setLevel(ERROR)
    driver = webdriver.Firefox(executable_path=GeckoDriverManager().install(),
                               options=options,
                               firefox_profile=profile)
    return driver
예제 #5
0
 def _create_firefox_options(api_obj):
     options = FirefoxOptions()
     args = set()
     if api_obj.browser_options_args:
         args.update(api_obj.browser_options_args)
     for arg in args:
         if arg:
             options.add_argument(arg)
     options.headless = api_obj.headless
     if api_obj.firefox_binary_path:
         options.binary_location = api_obj.firefox_binary_path
     if api_obj.firefox_profile_path:
         options.profile = api_obj.firefox_profile_path
     if api_obj.http_proxy:
         raw = {'proxyType': "manual", 'httpProxy': str(api_obj.http_proxy)}
         proxy = WebdriverProxy(raw=raw)
         options.proxy = proxy
     options.set_capability("acceptInsecureCerts",
                            False)  # why isnt this the default
     if api_obj.browser_options_dict:
         for k, v in api_obj.browser_options_dict.items():
             options.set_capability(k, v)
     return options
예제 #6
0
def get_used_books_from_kleinanzeigen(book):
    url = "https://www.ebay-kleinanzeigen.de/s-buecher-zeitschriften/c76"
    options = Options()
    options.headless = True
    options.set_capability("javascriptEnabled", True)

    SELENIUM_HOST = os.getenv("SELENIUM_HOST")
    SELENIUM_PORT = os.getenv("SELENIUM_PORT")
    command_executor = f"http://{SELENIUM_HOST}:{SELENIUM_PORT}/wd/hub"

    driver = webdriver.Remote(command_executor=command_executor,
                              desired_capabilities=options.to_capabilities())
    driver.get(url)  # books
    gdpr = WebDriverWait(driver, 10).until(
        EC.element_to_be_clickable((By.ID, "gdpr-banner-accept")))
    gdpr.click()

    search = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.ID, "site-search-query")))
    try:
        search.send_keys(book.title)
    except TypeError as e:
        raise TypeError(f"TE: {book.title} / {e}")
    search.send_keys(Keys.RETURN)

    time.sleep(5)
    results = driver.find_elements_by_id("srchrslt-adtable")

    if not results:
        return []

    result = results[0]
    assert result.tag_name == "ul"
    return [
        single_searchresult_to_bookoffer(item, book.isbn)
        for item in result.find_elements_by_class_name("lazyload-item")
    ]
예제 #7
0
import os
import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.options import Options

options = Options()
options.headless = True
options.set_capability("javascriptEnabled", True)

SELENIUM_HOST = os.getenv("SELENIUM_HOST")
SELENIUM_PORT = os.getenv("SELENIUM_PORT")

driver = webdriver.Remote(
    command_executor=f"http://{SELENIUM_HOST}:{SELENIUM_PORT}/wd/hub",
    desired_capabilities=options.to_capabilities())


wait = WebDriverWait(driver, 10)

driver.get("https://www.ebay-kleinanzeigen.de/s-buecher-zeitschriften/c76")  # books

gdpr = wait.until(EC.element_to_be_clickable((By.ID, "gdpr-banner-accept")))
gdpr.click()

search = wait.until(EC.presence_of_element_located((By.ID, "site-search-query")))
search.send_keys("Harry Potter")
예제 #8
0
    def __init__(self, id, database_creds, ng):
        self.cnxn = pyodbc.connect(database_creds.get_connectioN_string(),
                                   autocommit=True)
        self.ng = ng

        pid = os.getpid()

        cursor = self.cnxn.cursor()
        self.save_cursor = self.cnxn.cursor()
        option = Options()

        option.add_argument("--disable-infobars")

        option.add_argument("--disable-gpu")
        option.add_argument("--start-maximized")
        option.add_argument("--headless")
        option.add_argument("--window-size=1024,768")
        option.add_argument("--disable-extensions")
        option.add_argument("--disable-translate")
        option.add_argument("--allow-file-access-from-files")

        option.add_argument("--proxy-server='direct://'")
        option.add_argument("--proxy-bypass-list=*")
        option.add_argument("--start-maximized")
        option.add_argument('--disable-dev-shm-usage')
        option.add_argument('--no-sandbox')
        option.add_argument('--ignore-certificate-errors')

        # option.add_argument("--enable-usermedia-screen-capturing")
        # option.add_argument("--use-fake-ui-for-media-stream")
        # option.add_argument("--use-fake-device-for-media-stream")
        #  option.add_argument("--use-fake-ui-device-for-media-stream")
        #  option.add_argument("--use-file-for-fake-video-capture=C:\\temp\\bunnyvideo.mjpeg")
        #   option.add_argument("--use-file-for-fake-audio-capture=C:\\temp\\bunny.opus")
        option.add_argument("--enable-tracing")
        #  option.add_argument("--enable-tracing-output = c:\\temp\\log.txt")

        # Pass the argument 1 to allow and 2 to block
        #  option.add_experimental_option("prefs", {
        #     "profile.default_content_setting_values.notifications": 2
        #  })
        option.set_capability('unhandledPromptBehavior', 'accept')
        option.log.level = "trace"

        secret = Secret()

        fp = webdriver.FirefoxProfile()
        fp.set_preference("devtools.debugger.remote-enabled", True)
        fp.set_preference("devtools.debugger.prompt-connection", False)
        fp.set_preference("devtools.debugger.remote-enabled", True)

        fp.set_preference("marionette.log.level", "Trace")

        self.driver = webdriver.Remote(browser_profile=fp,
                                       command_executor=secret.URL,
                                       desired_capabilities={
                                           "browserName": "firefox",
                                           "marionette": "true"
                                       },
                                       options=option)

        self.step = Test()
        self.session = session.Session()
        self.master_id = id

        self.run()
예제 #9
0
    def get_web_driver_instance(self):
        """
       Get WebDriver Instance based on the browser configuration
        Returns:
            'WebDriver Instance'
        """

        chrome_options = Options()
        chrome_options.add_argument('--no-sandbox')
        chrome_options.add_argument('--disable-setuid-sandbox')
        chrome_options.add_argument('--start-maximized')
        chrome_options.add_argument("--kiosk")
        # # chrome_options.add_argument("--headless")
        # # chrome_options.binary_location = "C:\\path\\to\\chrome.exe"
        # chrome_options.add_argument('--remote-debugging-port=9222')
        chrome_options.add_argument('--disable-dev-shm-usage')
        chrome_options.add_argument('--disable-dev-shm-using')
        chrome_options.add_argument('disable-infobars')
        chrome_options.add_experimental_option("excludeSwitches",
                                               ['enable-automation'])
        # chrome_options.add_argument('--disable-gpu')
        chrome_options.add_argument('--disable-extensions')
        chrome_options.add_argument("--disable-extensions-file-access-check")
        chrome_options.add_argument('--disable-extensions-http-throttling')
        chrome_options.add_argument(
            '--disable-extensions --disable-extensions-file-access-check --disable-extensions-http-throttling'
        )
        cwd = os.getcwd()
        # display = Display(visible=0, size=(800, 600))
        # display.start()
        if self.browser == "iexplorer":
            # Set ie driver
            driver = webdriver.Ie()
        elif self.browser == "firefox":
            options = FirefoxOptions()
            options.set_capability('marionette', False)
            options.add_argument('--remote-debugging-port=9222')

            options.add_argument('--no-sandbox')
            options.add_argument('--disable-setuid-sandbox')
            options.add_argument('--start-maximized')
            options.add_argument("--kiosk")
            # # chrome_options.add_argument("--headless")
            # # chrome_options.binary_location = "C:\\path\\to\\chrome.exe"
            # chrome_options.add_argument('--remote-debugging-port=9222')
            options.add_argument('--disable-dev-shm-usage')
            options.add_argument('--disable-dev-shm-using')
            options.add_argument('disable-infobars')
            # chrome_options.add_argument('--disable-gpu')
            options.add_argument('--disable-extensions')
            options.add_argument("--disable-extensions-file-access-check")
            options.add_argument('--disable-extensions-http-throttling')
            options.add_argument(
                '--disable-extensions --disable-extensions-file-access-check --disable-extensions-http-throttling'
            )

            firefox_path = os.path.join(cwd, 'base', 'geckodriver')
            driver = webdriver.Firefox(executable_path=firefox_path,
                                       options=options)
        elif self.browser == "chrome":
            # Set chrome driver
            chrome_options.binary_location = "/usr/bin/google-chrome-stable"
            chrome_path = os.path.join(cwd, 'base', 'chromedriver')
            chrome_path = '/usr/local/bin/chromedriver'
            driver = webdriver.Chrome(chrome_path, options=chrome_options)
        else:
            driver = webdriver.Firefox()

        # Setting Driver Implicit Time out for An Element
        driver.implicitly_wait(3)
        # Maximize the window
        # Loading browser with App URL
        return driver