Example #1
0
 def get_chrome():
     return Chrome(
         service=ChromeService(
             ChromeDriverManager(
                 chrome_type=ChromeType.GOOGLE).install()),
         options=ChromeOptions(),
     )
Example #2
0
        def create_chrome():
            from selenium.webdriver.chrome.service import (
                Service as ChromeService, )

            return webdriver.Chrome(
                service=ChromeService(
                    ChromeDriverManager(
                        chrome_type=ChromeType.GOOGLE).install()),
                options=webdriver.ChromeOptions(),
            )
    def driver(self, request):
        _chromedriver = os.path.join(os.getcwd(), 'vendor', 'chromedriver')
        if os.path.isfile(_chromedriver):
            _service = ChromeService(executable_path=_chromedriver)
            driver_ = webdriver.Chrome(service=_service)
        else:
            driver_ = webdriver.Chrome()

        def quit():
            driver_.quit()

        request.addfinalizer(quit)
        return SecurePage(driver_)
Example #4
0
    def runChrome(self):
        self.options = webdriver.ChromeOptions()
        self.options.add_argument("--use-fake-ui-for-media-stream")
        self.options.add_argument("--disable-infobars")
        self.options.add_argument("--ignore-certificate-errors")
        self.options.add_argument("--start-maximized")
        self.options.add_argument("--use-fake-device-for-media-stream")
        self.options.add_argument("--no-sandbox")

        self.driver = webdriver.Chrome(service=ChromeService(
            ChromeDriverManager().install()),
                                       options=self.options)
        self.driver.implicitly_wait(15)
def driver(request):
    config.baseurl = request.config.getoption("--baseurl")
    config.host = request.config.getoption("--host").lower()
    config.browser = request.config.getoption("--browser").lower()
    config.browserversion = request.config.getoption(
        "--browserversion").lower()
    config.platform = request.config.getoption("--platform").lower()

    if config.host == "saucelabs":
        _desired_caps = {}
        _desired_caps["browserName"] = config.browser
        _desired_caps["browserVersion"] = config.browserversion
        _desired_caps["platformName"] = config.platform
        _desired_caps["name"] = request.cls.__name__ + \
            "." + request.function.__name__
        _credentials = os.environ["SAUCE_USERNAME"] + \
            ":" + os.environ["SAUCE_ACCESS_KEY"]
        _url = "http://" + _credentials + "@ondemand.saucelabs.com:80/wd/hub"
        driver_ = webdriver.Remote(_url, _desired_caps)
    elif config.host == "localhost":
        if config.browser == "firefox":
            _geckodriver = os.path.join(os.getcwd(), 'vendor', 'geckodriver')
            if os.path.isfile(_geckodriver):
                _service = FirefoxService(executable_path=_geckodriver)
                driver_ = webdriver.Firefox(executable_path=_geckodriver)
            else:
                driver_ = webdriver.Firefox()
        elif config.browser == "chrome":
            _chromedriver = os.path.join(
                os.getcwd() + 'vendor', 'chromedriver')
            if os.path.isfile(_chromedriver):
                _service = ChromeService(executable_path=_geckodriver)
                driver_ = webdriver.Chrome(service=_service)
            else:
                driver_ = webdriver.Chrome()

    def quit():
        try:
            if config.host == "saucelabs":
                if request.node.result_call.failed:
                    driver_.execute_script("sauce:job-result=failed")
                    print "http://saucelabs.com/tests/" + driver_.session_id
                elif request.node.result_call.passed:
                    driver_.execute_script("sauce:job-result=passed")
        finally:
            driver_.quit()

    request.addfinalizer(quit)
    return driver_
Example #6
0
    def setUp(self):
        super(ChromiumWebDriverFixture, self).setUp()
        # Import late to avoid hard dependency.
        from selenium.webdriver.chrome.service import Service as ChromeService
        service = ChromeService("/usr/lib/chromium-browser/chromedriver", 4444)

        # Set the LD_LIBRARY_PATH so the chrome driver can find the required
        # libraries.
        self.useFixture(
            EnvironmentVariable("LD_LIBRARY_PATH",
                                "/usr/lib/chromium-browser/libs"))
        service.start()

        # Stop service on cleanup.
        self.addCleanup(service.stop)
Example #7
0
def work_loop(thread_name, tid):
    global thread_busy
    global stock_codes

    print(('{t} Started'.format(t=thread_name)))
    options = webdriver.ChromeOptions()

    from selenium.webdriver.chrome.options import Options

    options = Options()
    #opt.add_experimental_option("prefs", {
    #  "download.default_directory": r"C:/Users/Future/Desktop",
    #  "download.prompt_for_download": False,
    #  "download.directory_upgrade": True,
    #  "safebrowsing_for_trusted_sources_enabled": False,
    #  "safebrowsing.enabled": False
    #})

    #options.add_argument("")
    options.add_experimental_option("prefs", preferences)
    #options.add_argument('headless')
    #options.add_argument('window-size=0x0')
    #driver = webdriver.Chrome('/home/anshul/web/analytics/analytics/chromedriver_linux64/chromedriver',chrome_options=options)
    service = ChromeService(executable_path=ChromeDriverManager().install())
    driver = webdriver.Chrome(service=service)
    driver.implicitly_wait(
        10
    )  #seconds: After page load, some classes may load up by JS. So, wait if not available

    for stock in stock_codes:
        if not os.path.exists(download_dir +
                              "{file_name}".format(file_name=stock.code) +
                              ".csv"):
            #time.sleep(1)
            ret_val = download_data(driver, base_url % stock.code)
            while ret_val is not True:
                print(('Retry {name}'.format(name=stock.name)))
                time.sleep(2)
                ret_val = download_data(driver, base_url % stock.code)
        else:
            print(("Skipping %s" % stock.name))
    thread_busy[0] = 0
    print(('{t} done'.format(t=thread_name)))
    driver.close()
    driver.quit()
def driver(request):
    config.baseurl = request.config.getoption("--baseurl")
    config.host = request.config.getoption("--host").lower()
    config.browser = request.config.getoption("--browser").lower()
    config.browserversion = request.config.getoption(
        "--browserversion").lower()
    config.platform = request.config.getoption("--platform").lower()

    if config.host == "saucelabs":
        _desired_caps = {}
        _desired_caps["browserName"] = config.browser
        _desired_caps["browserVersion"] = config.browserversion
        _desired_caps["platformName"] = config.platform
        _credentials = os.environ["SAUCE_USERNAME"] + \
            ":" + os.environ["SAUCE_ACCESS_KEY"]
        _url = "http://" + _credentials + "@ondemand.saucelabs.com:80/wd/hub"
        driver_ = webdriver.Remote(_url, _desired_caps)
    elif config.host == "localhost":
        if config.browser == "firefox":
            _geckodriver = os.path.join(os.getcwd(), 'vendor', 'geckodriver')
            if os.path.isfile(_geckodriver):
                _service = FirefoxService(executable_path=_geckodriver)
                driver_ = webdriver.Firefox(executable_path=_geckodriver)
            else:
                driver_ = webdriver.Firefox()
        elif config.browser == "chrome":
            _chromedriver = os.path.join(os.getcwd() + 'vendor',
                                         'chromedriver')
            if os.path.isfile(_chromedriver):
                _service = ChromeService(executable_path=_geckodriver)
                driver_ = webdriver.Chrome(service=_service)
            else:
                driver_ = webdriver.Chrome()

    def quit():
        driver_.quit()

    request.addfinalizer(quit)
    return driver_
Example #9
0
def get_chromedriver(options=None, settings=None):
    """Get chromedriver automatically.

    Args:
        options (selenium.webdriver.chrome.options.Options, optional):
            Options to start chromedriver with. If None, will use default
            settings. Defaults to None.
        settings (scrapy.settings.Settings, optional): Scrapy settings to
            take into consideration when starting chromedriver. If None,
            will not be taken into consideration. Defaults to None.

    Returns:
        Selenium webdriver for Chrome (selenium.webdriver.Chrome).
    """
    settings = settings or {}
    if options is None:
        options = Options()
        options.add_argument('--no-sandbox')
        options.add_argument("--disable-extensions")
        options.add_argument("--disable-gpu")
        options.add_argument('--disable-dev-shm-usage')
        options.add_experimental_option('prefs',
                                        {'intl.accept_languages': 'fi,fi_FI'})
        if not settings.get('DISABLE_HEADLESS', False):
            options.add_argument("--headless")
        if settings.get('PROGRESS_BAR_ENABLED', True):
            options.add_argument('--disable-logging')

    service = ChromeService(ChromeDriverManager().install())
    driver = webdriver.Chrome(service=service, options=options)
    if settings.get('MINIMIZE_WINDOW', False):
        try:
            driver.minimize_window()
        except WebDriverException:
            pass

    return driver
Example #10
0
def driver(request):
    config.baseurl = request.config.getoption("--baseurl")
    config.browser = request.config.getoption("--browser").lower()

    if config.browser == "firefox":
        _geckodriver = os.path.join(os.getcwd(), 'vendor', 'geckodriver')
        if os.path.isfile(_geckodriver):
            _service = FirefoxService(executable_path=_geckodriver)
            driver_ = webdriver.Firefox(service=_service)
        else:
            driver_ = webdriver.Firefox()
    elif config.browser == "chrome":
        _chromedriver = os.path.join(os.getcwd() + 'vendor', 'chromedriver')
        if os.path.isfile(_chromedriver):
            _service = ChromeService(executable_path=_geckodriver)
            driver_ = webdriver.Chrome(service=_service)
        else:
            driver_ = webdriver.Chrome()

    def quit():
        driver_.quit()

    request.addfinalizer(quit)
    return driver_
Example #11
0
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

service = ChromeService(executable_path="/opt/homebrew/bin/chromedriver")
driver = webdriver.Chrome(service=service)

driver.get("https://secure-retreat-92358.herokuapp.com/")
fName = driver.find_element(By.NAME, "fName")
fName.send_keys("Gizat")

lName = driver.find_element(By.NAME, "lName")
lName.send_keys("Makhanov")

email = driver.find_element(By.NAME, "email")
email.send_keys("*****@*****.**")

email.send_keys(Keys.ENTER)
Example #12
0
def get_playlist_videos(url, resolution, aquire_wait_time, starting_video,
                        ending_video):
    # --------------------------
    # Start Browser Service
    # --------------------------
    driver_path = os.getcwd() + '/chromedriver'
    try:
        service = ChromeService(driver_path)
        service.start()
        options = {}
        driver = webdriver.Remote(service.service_url, options)
        driver.implicitly_wait(3)
    except:
        print(
            "Error occurred. Probably the chromedriver is missing. Keep the executable chromedriver file in the same directory as the Youtube Downloader!"
        )
        while (1):
            time.sleep(1)

    # --------------------------
    # Go to Playlist Page
    # --------------------------
    print("Indexing video list...")
    list_url = 'https://www.youtube.com/playlist?list=' + url[
        (url.index("list=") + 5):]
    driver.get(list_url)
    time.sleep(3)

    # --------------------------
    # Click to Load Content
    # --------------------------
    there_is_more_to_load = True
    while there_is_more_to_load:
        try:
            load_more = driver.find_element_by_class_name("load-more-text")
            driver.implicitly_wait(5)
            load_more.click()
            time.sleep(3)
        except:
            there_is_more_to_load = False

    # --------------------------
    # Get Page Source
    # --------------------------
    page = bs4.BeautifulSoup(driver.page_source, 'html.parser')

    # --------------------------
    # Extract Video Info
    # --------------------------
    list_name = page.select(
        'a[class="yt-simple-endpoint style-scope yt-formatted-string"]'
    )[0].text
    yt_link_list = []
    ss_link_list = []
    name_list = []
    second_inner = page.find_all(
        "div", {
            "id": "contents",
            "class": "style-scope ytd-playlist-video-list-renderer"
        })
    last_div = second_inner[0].find_all("div", {
        "class": "style-scope ytd-playlist-video-renderer",
        "id": "content"
    })

    for video in last_div:
        name_list.append(
            video.find_all("span", id="video-title")[0].text[17:-15])
        yt_link_list.append("http://ssyoutube.com" +
                            video.find_all("a")[0]['href'])
    starting_video = int(starting_video) - 1
    ending_video = int(ending_video)
    if ending_video > len(name_list):
        ending_video = len(name_list)

    for i in range(0, len(name_list)):
        if (i >= starting_video) and (i < ending_video):
            try:
                print("Acquiring video: " + name_list[i])
                driver.get(yt_link_list[i])
                time.sleep(int(aquire_wait_time))
                ss_link_list.append(
                    bs4.BeautifulSoup(
                        driver.page_source, 'html.parser').find_all(
                            "a", {"title": "video format: " + resolution
                                  })[0]['href'])
            except KeyboardInterrupt:
                ss_link_list.append("")
                print("Skipping...")
                continue
            except Exception:
                ss_link_list.append("")
                print("Acquiring failed! Resolution might not be available.")
        else:
            ss_link_list.append("")

    driver.close()
    return list_name, name_list, ss_link_list, starting_video, ending_video
Example #13
0
def test_driver_manager_chrome():
    service = ChromeService(executable_path=ChromeDriverManager().install())

    driver = webdriver.Chrome(service=service)

    driver.quit()
Example #14
0
def setup():
    chrome_service = ChromeService(driver_path)
    driver = webdriver.Chrome(service=chrome_service)
    print("Launching chrome browser...")
    return driver