def safari_browser():
    driver = webdriver.Safari()
    driver.maximize_window()
    yield driver
    driver.quit()
Beispiel #2
0
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep

safari = webdriver.Safari()
safari.get("http://www.python.org")
try:
    safari.implicitly_wait(3)
    # elem = safari.find_element_by_name('q')
    # elem.clear()
    # elem.send_keys('pycon')
    # elem.send_keys(Keys.RETURN)
    # # alert = safari.switch_to.alert
    # sleep(10)
    # safari.back()
    elem = safari.find_element_by_id('about')
    all_elem = elem.find_elements_by_tag_name('li')
    # print(all_elem)
    for option in all_elem:
        print(option.get_attribute('value'))

except Exception as ex:
    print(ex)
finally:
    safari.close()
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.firefox import GeckoDriverManager
from webdriver_manager.opera import OperaDriverManager

browserName = "chrome"

if browserName == "chrome":
    driver = webdriver.Chrome(ChromeDriverManager().install())
elif browserName == "firefox":
    driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
elif browserName == "safari":
    driver = webdriver.Safari(executable_path=OperaDriverManager().install())
else:
    print("please pass the correct browser name: " + browserName)
    raise Exception('driver not found')

driver.implicitly_wait(10)
driver.get("https://app.hubspot.com/")

print(driver.title)

driver.find_element(By.ID, 'username').send_keys("*****@*****.**")
driver.find_element(By.ID, 'password').send_keys("Adworker_78")
driver.find_element(By.ID, 'loginBtn').click()

time.sleep(5)
driver.quit()
def driver():
    # _driver = webdriver.Chrome()
    _driver = webdriver.Safari()
    _driver.implicitly_wait(5)
    yield _driver
    _driver.quit()
Beispiel #5
0
username = ""
#enter your login password
password = ""

###########################################################

#enter the element for username input field
element_for_username = ""
#enter the element for password input field
element_for_password = ""
#enter the element for submit button
element_for_submit = ""

###########################################################

browser = webdriver.Safari(
)  #for macOS users[for others use chrome vis chromedriver]
#browser = webdriver.Chrome()	#uncomment this line,for chrome users
browser.get((website_link))

try:
    username_element = browser.find_element_by_name(element_for_username)
    username_element.send_keys(username)
    password_element = browser.find_element_by_name(element_for_password)
    password_element.send_keys(password)
    signInButton = browser.find_element_by_name(element_for_submit)
    signInButton.click()

    #### to quit the browser uncomment the following lines ####
    # time.sleep(3)
    # browser.quit()
    # time.sleep(1)
#this album pulls only the past two days' album reviews
#meant for once you have a large set of all the prior album reviews, and want to continuously update that dataset

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from time import sleep
import datetime
import json
import csv
import urllib

# don't mess with these variables
delay = 5 # time to wait on each page load before reading the page
driver = webdriver.Safari() # options are Chrome(), Safari(), Firefox()
album_selector = 'h1.review-title'
artist_selector = 'ul.artist-links li'
score_selector = 'span.score'
record_label_selector = 'ul.label-list li'
year_selector = 'span.year'
review_author_selector = 'ul.authors-detail a'
genre_selector = 'ul.genre-list a'
date_published_selector = 'time.pub-date'
abstract_selector = 'div.abstract'
accolades_selector = 'p.bnm-txt'
album_art_selector = 'div.album-art img'
artist_url_selector = 'ul.artist-links li a'

day = datetime.date.today().strftime("%d")
previous = int(day) - 1
def get_local_driver(browser_name, headless, locale_code, servername,
                     proxy_string, proxy_auth, proxy_user, proxy_pass,
                     user_agent, disable_csp, enable_ws, enable_sync,
                     use_auto_ext, no_sandbox, disable_gpu, incognito,
                     guest_mode, devtools, remote_debug, swiftshader,
                     block_images, chromium_arg, user_data_dir, extension_zip,
                     extension_dir, mobile_emulator, device_width,
                     device_height, device_pixel_ratio):
    '''
    Spins up a new web browser and returns the driver.
    Can also be used to spin up additional browsers for the same test.
    '''
    downloads_path = download_helper.get_downloads_folder()

    if browser_name == constants.Browser.FIREFOX:
        firefox_options = _set_firefox_options(downloads_path, headless,
                                               locale_code, proxy_string,
                                               user_agent, disable_csp)
        if LOCAL_GECKODRIVER and os.path.exists(LOCAL_GECKODRIVER):
            try:
                make_driver_executable_if_not(LOCAL_GECKODRIVER)
            except Exception as e:
                logging.debug("\nWarning: Could not make geckodriver"
                              " executable: %s" % e)
        elif not is_geckodriver_on_path():
            args = " ".join(sys.argv)
            if not ("-n" in sys.argv or "-n=" in args or args == "-c"):
                # (Not multithreaded)
                from seleniumbase.console_scripts import sb_install
                sys_args = sys.argv  # Save a copy of current sys args
                print("\nWarning: geckodriver not found!" " Installing now:")
                try:
                    sb_install.main(override="geckodriver")
                except Exception as e:
                    print("\nWarning: Could not install geckodriver: "
                          "%s" % e)
                sys.argv = sys_args  # Put back the original sys args
        warnings.simplefilter("ignore", category=DeprecationWarning)
        return webdriver.Firefox(options=firefox_options)
    elif browser_name == constants.Browser.INTERNET_EXPLORER:
        if not IS_WINDOWS:
            raise Exception(
                "IE Browser is for Windows-based operating systems only!")
        from selenium.webdriver.ie.options import Options
        ie_options = Options()
        ie_options.ignore_protected_mode_settings = True
        ie_options.ignore_zoom_level = True
        ie_options.require_window_focus = False
        ie_options.native_events = True
        ie_options.full_page_screenshot = True
        ie_options.persistent_hover = True
        ie_capabilities = ie_options.to_capabilities()
        if LOCAL_IEDRIVER and os.path.exists(LOCAL_IEDRIVER):
            try:
                make_driver_executable_if_not(LOCAL_IEDRIVER)
            except Exception as e:
                logging.debug("\nWarning: Could not make iedriver"
                              " executable: %s" % e)
        return webdriver.Ie(capabilities=ie_capabilities)
    elif browser_name == constants.Browser.EDGE:
        try:
            chrome_options = _set_chrome_options(
                browser_name, downloads_path, headless, locale_code,
                proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
                disable_csp, enable_ws, enable_sync, use_auto_ext, no_sandbox,
                disable_gpu, incognito, guest_mode, devtools, remote_debug,
                swiftshader, block_images, chromium_arg, user_data_dir,
                extension_zip, extension_dir, servername, mobile_emulator,
                device_width, device_height, device_pixel_ratio)
            if LOCAL_EDGEDRIVER and os.path.exists(LOCAL_EDGEDRIVER):
                try:
                    make_driver_executable_if_not(LOCAL_EDGEDRIVER)
                except Exception as e:
                    logging.debug("\nWarning: Could not make edgedriver"
                                  " executable: %s" % e)
            elif not is_edgedriver_on_path():
                args = " ".join(sys.argv)
                if not ("-n" in sys.argv or "-n=" in args or args == "-c"):
                    # (Not multithreaded)
                    from seleniumbase.console_scripts import sb_install
                    sys_args = sys.argv  # Save a copy of current sys args
                    print("\nWarning: msedgedriver not found. Installing now:")
                    sb_install.main(override="edgedriver")
                    sys.argv = sys_args  # Put back the original sys args
            # For Microsoft Edge (Chromium) version 79 or lower
            return webdriver.Chrome(executable_path=LOCAL_EDGEDRIVER,
                                    options=chrome_options)
        except Exception:
            # For Microsoft Edge (Chromium) version 80 or higher
            from msedge.selenium_tools import Edge, EdgeOptions
            if LOCAL_EDGEDRIVER and os.path.exists(LOCAL_EDGEDRIVER):
                try:
                    make_driver_executable_if_not(LOCAL_EDGEDRIVER)
                except Exception as e:
                    logging.debug("\nWarning: Could not make edgedriver"
                                  " executable: %s" % e)
            edge_options = EdgeOptions()
            edge_options.use_chromium = True
            prefs = {
                "download.default_directory": downloads_path,
                "local_discovery.notifications_enabled": False,
                "credentials_enable_service": False,
                "download.prompt_for_download": False,
                "download.directory_upgrade": True,
                "safebrowsing.enabled": False,
                "safebrowsing.disable_download_protection": True,
                "default_content_setting_values.notifications": 0,
                "default_content_settings.popups": 0,
                "managed_default_content_settings.popups": 0,
                "content_settings.exceptions.automatic_downloads.*.setting": 1,
                "profile.password_manager_enabled": False,
                "profile.default_content_setting_values.notifications": 0,
                "profile.default_content_settings.popups": 0,
                "profile.managed_default_content_settings.popups": 0,
                "profile.default_content_setting_values.automatic_downloads": 1
            }
            if locale_code:
                prefs["intl.accept_languages"] = locale_code
            if block_images:
                prefs["profile.managed_default_content_settings.images"] = 2
            edge_options.add_experimental_option("prefs", prefs)
            edge_options.add_experimental_option("w3c", True)
            edge_options.add_argument(
                "--disable-blink-features=AutomationControlled")
            edge_options.add_experimental_option("useAutomationExtension",
                                                 False)
            edge_options.add_experimental_option(
                "excludeSwitches", ["enable-automation", "enable-logging"])
            if guest_mode:
                edge_options.add_argument("--guest")
            if headless:
                edge_options.add_argument("--headless")
            if mobile_emulator:
                emulator_settings = {}
                device_metrics = {}
                if type(device_width) is int and (
                        type(device_height) is int and
                    (type(device_pixel_ratio) is int)):
                    device_metrics["width"] = device_width
                    device_metrics["height"] = device_height
                    device_metrics["pixelRatio"] = device_pixel_ratio
                else:
                    device_metrics["width"] = 411
                    device_metrics["height"] = 731
                    device_metrics["pixelRatio"] = 3
                emulator_settings["deviceMetrics"] = device_metrics
                if user_agent:
                    emulator_settings["userAgent"] = user_agent
                edge_options.add_experimental_option("mobileEmulation",
                                                     emulator_settings)
                edge_options.add_argument("--enable-sync")
            if user_data_dir:
                abs_path = os.path.abspath(user_data_dir)
                edge_options.add_argument("user-data-dir=%s" % abs_path)
            if extension_zip:
                # Can be a comma-separated list of .ZIP or .CRX files
                extension_zip_list = extension_zip.split(',')
                for extension_zip_item in extension_zip_list:
                    abs_path = os.path.abspath(extension_zip_item)
                    edge_options.add_extension(abs_path)
            if extension_dir:
                # load-extension input can be a comma-separated list
                abs_path = os.path.abspath(extension_dir)
                edge_options.add_argument("--load-extension=%s" % abs_path)
            edge_options.add_argument("--disable-infobars")
            edge_options.add_argument("--disable-save-password-bubble")
            edge_options.add_argument("--disable-single-click-autofill")
            edge_options.add_argument(
                "--disable-autofill-keyboard-accessory-view[8]")
            edge_options.add_argument("--disable-translate")
            if not enable_ws:
                edge_options.add_argument("--disable-web-security")
            edge_options.add_argument("--homepage=about:blank")
            edge_options.add_argument("--dns-prefetch-disable")
            edge_options.add_argument("--dom-automation")
            edge_options.add_argument("--disable-hang-monitor")
            edge_options.add_argument("--disable-prompt-on-repost")
            if (settings.DISABLE_CSP_ON_CHROME
                    or disable_csp) and (not headless):
                # Headless Edge doesn't support extensions, which are required
                # for disabling the Content Security Policy on Edge
                edge_options = _add_chrome_disable_csp_extension(edge_options)
                edge_options.add_argument("--enable-sync")
            if proxy_string:
                if proxy_auth:
                    edge_options = _add_chrome_proxy_extension(
                        edge_options, proxy_string, proxy_user, proxy_pass)
                edge_options.add_argument("--proxy-server=%s" % proxy_string)
            edge_options.add_argument("--test-type")
            edge_options.add_argument("--log-level=3")
            edge_options.add_argument("--no-first-run")
            edge_options.add_argument("--ignore-certificate-errors")
            if devtools and not headless:
                edge_options.add_argument("--auto-open-devtools-for-tabs")
            edge_options.add_argument("--allow-file-access-from-files")
            edge_options.add_argument("--allow-insecure-localhost")
            edge_options.add_argument("--allow-running-insecure-content")
            if user_agent:
                edge_options.add_argument("--user-agent=%s" % user_agent)
            edge_options.add_argument("--no-sandbox")
            if remote_debug:
                # To access the Remote Debugger, go to: http://localhost:9222
                # while a Chromium driver is running.
                # Info: https://chromedevtools.github.io/devtools-protocol/
                edge_options.add_argument("--remote-debugging-port=9222")
            if swiftshader:
                edge_options.add_argument("--use-gl=swiftshader")
            else:
                edge_options.add_argument("--disable-gpu")
            if "linux" in PLATFORM:
                edge_options.add_argument("--disable-dev-shm-usage")
            if chromium_arg:
                # Can be a comma-separated list of Chromium args
                chromium_arg_list = chromium_arg.split(',')
                for chromium_arg_item in chromium_arg_list:
                    chromium_arg_item = chromium_arg_item.strip()
                    if not chromium_arg_item.startswith("--"):
                        if chromium_arg_item.startswith("-"):
                            chromium_arg_item = "-" + chromium_arg_item
                        else:
                            chromium_arg_item = "--" + chromium_arg_item
                    if len(chromium_arg_item) >= 3:
                        edge_options.add_argument(chromium_arg_item)
            capabilities = edge_options.to_capabilities()
            capabilities["platform"] = ''
            return Edge(executable_path=LOCAL_EDGEDRIVER,
                        capabilities=capabilities)
    elif browser_name == constants.Browser.SAFARI:
        arg_join = " ".join(sys.argv)
        if ("-n" in sys.argv) or ("-n=" in arg_join) or (arg_join == "-c"):
            # Skip if multithreaded
            raise Exception("Can't run Safari tests in multi-threaded mode!")
        safari_capabilities = _set_safari_capabilities()
        return webdriver.Safari(desired_capabilities=safari_capabilities)
    elif browser_name == constants.Browser.OPERA:
        try:
            if LOCAL_OPERADRIVER and os.path.exists(LOCAL_OPERADRIVER):
                try:
                    make_driver_executable_if_not(LOCAL_OPERADRIVER)
                except Exception as e:
                    logging.debug("\nWarning: Could not make operadriver"
                                  " executable: %s" % e)
            opera_options = _set_chrome_options(
                browser_name, downloads_path, headless, locale_code,
                proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
                disable_csp, enable_ws, enable_sync, use_auto_ext, no_sandbox,
                disable_gpu, incognito, guest_mode, devtools, remote_debug,
                swiftshader, block_images, chromium_arg, user_data_dir,
                extension_zip, extension_dir, servername, mobile_emulator,
                device_width, device_height, device_pixel_ratio)
            opera_options.headless = False  # No support for headless Opera
            return webdriver.Opera(options=opera_options)
        except Exception:
            return webdriver.Opera()
    elif browser_name == constants.Browser.PHANTOM_JS:
        with warnings.catch_warnings():
            # Ignore "PhantomJS has been deprecated" UserWarning
            warnings.simplefilter("ignore", category=UserWarning)
            return webdriver.PhantomJS()
    elif browser_name == constants.Browser.GOOGLE_CHROME:
        try:
            chrome_options = _set_chrome_options(
                browser_name, downloads_path, headless, locale_code,
                proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
                disable_csp, enable_ws, enable_sync, use_auto_ext, no_sandbox,
                disable_gpu, incognito, guest_mode, devtools, remote_debug,
                swiftshader, block_images, chromium_arg, user_data_dir,
                extension_zip, extension_dir, servername, mobile_emulator,
                device_width, device_height, device_pixel_ratio)
            if LOCAL_CHROMEDRIVER and os.path.exists(LOCAL_CHROMEDRIVER):
                try:
                    make_driver_executable_if_not(LOCAL_CHROMEDRIVER)
                except Exception as e:
                    logging.debug("\nWarning: Could not make chromedriver"
                                  " executable: %s" % e)
            elif not is_chromedriver_on_path():
                args = " ".join(sys.argv)
                if not ("-n" in sys.argv or "-n=" in args or args == "-c"):
                    # (Not multithreaded)
                    from seleniumbase.console_scripts import sb_install
                    sys_args = sys.argv  # Save a copy of current sys args
                    print("\nWarning: chromedriver not found. Installing now:")
                    sb_install.main(override="chromedriver")
                    sys.argv = sys_args  # Put back the original sys args
            if not headless or "linux" not in PLATFORM:
                return webdriver.Chrome(options=chrome_options)
            else:  # Running headless on Linux
                try:
                    return webdriver.Chrome(options=chrome_options)
                except Exception:
                    # Use the virtual display on Linux during headless errors
                    logging.debug("\nWarning: Chrome failed to launch in"
                                  " headless mode. Attempting to use the"
                                  " SeleniumBase virtual display on Linux...")
                    chrome_options.headless = False
                    return webdriver.Chrome(options=chrome_options)
        except Exception as e:
            if headless:
                raise Exception(e)
            if LOCAL_CHROMEDRIVER and os.path.exists(LOCAL_CHROMEDRIVER):
                try:
                    make_driver_executable_if_not(LOCAL_CHROMEDRIVER)
                except Exception as e:
                    logging.debug("\nWarning: Could not make chromedriver"
                                  " executable: %s" % e)
            return webdriver.Chrome()
    else:
        raise Exception("%s is not a valid browser option for this system!" %
                        browser_name)
Beispiel #8
0
 def launch(self, desired_capabilities=None, options=None):
     from selenium.webdriver import DesiredCapabilities
     self._set_config()
     if self._automation_browser == CHROME and self._automation_local:
         self.setup_chromedriver()
         chrome_capabilities = DesiredCapabilities.CHROME.copy()
         if options is not None:
             chrome_capabilities.update(options.to_capabilities())
             if desired_capabilities is not None:
                 chrome_capabilities.update(desired_capabilities)
         else:
             if desired_capabilities is not None:
                 chrome_capabilities.update(desired_capabilities)
         return webdriver.Chrome(desired_capabilities=chrome_capabilities)
     if self._automation_browser == GECKO and self._automation_local:
         self.setup_geckodriver()
         firefox_capabilities = DesiredCapabilities.FIREFOX.copy()
         if options is not None:
             firefox_capabilities.update(options.to_capabilities())
             if desired_capabilities is not None:
                 firefox_capabilities.update(desired_capabilities)
         else:
             if desired_capabilities is not None:
                 firefox_capabilities.update(desired_capabilities)
         return webdriver.Firefox(desired_capabilities=firefox_capabilities,
                                  service_log_path=os.path.join(ROOT_DIR, LOG_DIR, f'{GECKODRIVER}{LOG}'))
     if self._automation_browser == EDGE:
         self.setup_edgedriver()
         from msedge.selenium_tools import Edge, EdgeOptions
         edge_capabilities = DesiredCapabilities.EDGE.copy()
         if options is not None:
             edge_capabilities.update(options.to_capabilities())
             if desired_capabilities is not None:
                 edge_capabilities.update(desired_capabilities)
         else:
             if desired_capabilities is not None:
                 edge_capabilities.update(desired_capabilities)
         from msedge.selenium_tools import Edge, EdgeOptions
         edge_options = EdgeOptions()
         edge_options.use_chromium = True
         edge_options.set_capability('platform', 'MAC' if OS_NAME == 'MAC' else 'WINDOWS')
         edge_capabilities.update(edge_options.to_capabilities())
         return Edge(desired_capabilities=edge_options.to_capabilities())
     if self._automation_browser == IE:
         if OS_NAME == 'MAC':
             raise NotImplementedError('Cannot launch IE browser on Mac.')
         self.setup_iedriver()
         ie_capabilities = DesiredCapabilities.INTERNETEXPLORER.copy()
         if options is not None:
             ie_capabilities.update(options.to_capabilities())
             if desired_capabilities is not None:
                 ie_capabilities.update(desired_capabilities)
         else:
             if desired_capabilities is not None:
                 ie_capabilities.update(desired_capabilities)
         from selenium.webdriver import IeOptions
         ie_options = IeOptions()
         ie_options.ignore_protected_mode_settings = True
         ie_options.ensure_clean_session = True
         ie_options.require_window_focus = True
         ie_options.ignore_zoom_level = True
         ie_capabilities.update(ie_options.to_capabilities())
         return webdriver.Ie(desired_capabilities=ie_capabilities)
     if self._automation_browser == SAFARI:
         if OS_NAME == 'WIN':
             raise NotImplementedError('Cannot launch safari browser on Windows.')
         return webdriver.Safari(desired_capabilities=desired_capabilities)
     remote_capabilities = DesiredCapabilities.CHROME.copy() if self._automation_browser == CHROME \
         else DesiredCapabilities.FIREFOX.copy()
     if options is not None:
         remote_capabilities.update(options.to_capabilities())
         if desired_capabilities is not None:
             remote_capabilities.update(desired_capabilities)
     else:
         if desired_capabilities is not None:
             remote_capabilities.update(desired_capabilities)
     return webdriver.Remote(command_executor=self._automation_url, desired_capabilities=remote_capabilities)
Beispiel #9
0
 def launch_driver(self, url, options, browser_build_path):
     import webkitpy.thirdparty.autoinstalled.selenium
     from selenium import webdriver
     driver = webdriver.Safari(quiet=False)
     self._launch_webdriver(url=url, driver=driver)
     return driver
Beispiel #10
0
 def test0(self):
     driver = webdriver.Safari()
     # edit the next line to enter the location of "min.html" on your system
     driver.get(
         r"file:///Users/jakeyoon/Documents/2020Fall/EE461L/tutorial8/part2/min.html"
     )
     elem = driver.find_element_by_id("x")
     elem.send_keys("0")  # enter a representative for x
     elem = driver.find_element_by_id("y")
     elem.send_keys("0")  # enter a representative for y
     elem = driver.find_element_by_id("z")
     elem.send_keys("0")  # enter a representative for z
     elem = driver.find_element_by_id("computeButton")
     elem.click()  #click the button
     result = driver.find_element_by_id("result")
     output = result.text  # read the output text
     self.assertEqual("min(0, 0, 0) = 0", output)
     time.sleep(2)
     driver.get(
         r"file:///Users/jakeyoon/Documents/2020Fall/EE461L/tutorial8/part2/min.html"
     )
     elem = driver.find_element_by_id("x")
     elem.send_keys("0")  # enter a representative for x
     elem = driver.find_element_by_id("y")
     elem.send_keys("0")  # enter a representative for y
     elem = driver.find_element_by_id("z")
     elem.send_keys("1")  # enter a representative for z
     elem = driver.find_element_by_id("computeButton")
     elem.click()  #click the button
     result = driver.find_element_by_id("result")
     output = result.text  # read the output text
     self.assertEqual("min(0, 0, 1) = 0", output)
     time.sleep(2)
     driver.get(
         r"file:///Users/jakeyoon/Documents/2020Fall/EE461L/tutorial8/part2/min.html"
     )
     elem = driver.find_element_by_id("x")
     elem.send_keys("-1")  # enter a representative for x
     elem = driver.find_element_by_id("y")
     elem.send_keys("1")  # enter a representative for y
     elem = driver.find_element_by_id("z")
     elem.send_keys("1")  # enter a representative for z
     result = driver.find_element_by_id("result")
     output = result.text  # read the output text
     self.assertEqual("", output)
     time.sleep(2)
     driver.get(
         r"file:///Users/jakeyoon/Documents/2020Fall/EE461L/tutorial8/part2/min.html"
     )
     elem = driver.find_element_by_id("x")
     elem.send_keys("1")  # enter a representative for x
     elem = driver.find_element_by_id("y")
     elem.send_keys("1")  # enter a representative for y
     elem = driver.find_element_by_id("z")
     elem.send_keys("-1")  # enter a representative for z
     elem = driver.find_element_by_id("computeButton")
     elem.click()  #click the button
     result = driver.find_element_by_id("result")
     output = result.text  # read the output text
     self.assertEqual("min(1, 1, -1) = -1", output)
     time.sleep(2)
     driver.get(
         r"file:///Users/jakeyoon/Documents/2020Fall/EE461L/tutorial8/part2/min.html"
     )
     elem = driver.find_element_by_id("x")
     elem.send_keys("1")  # enter a representative for x
     elem = driver.find_element_by_id("y")
     elem.send_keys("0")  # enter a representative for y
     elem = driver.find_element_by_id("z")
     elem.send_keys("-1")  # enter a representative for z
     result = driver.find_element_by_id("result")
     output = result.text  # read the output text
     self.assertEqual("", output)
     time.sleep(2)
     driver.get(
         r"file:///Users/jakeyoon/Documents/2020Fall/EE461L/tutorial8/part2/min.html"
     )
     elem = driver.find_element_by_id("x")
     elem.send_keys("0")  # enter a representative for x
     elem = driver.find_element_by_id("y")
     elem.send_keys("-1")  # enter a representative for y
     elem = driver.find_element_by_id("z")
     elem.send_keys("-1")  # enter a representative for z
     elem = driver.find_element_by_id("computeButton")
     elem.click()  #click the button
     result = driver.find_element_by_id("result")
     output = result.text  # read the output text
     self.assertEqual("min(1, 1, -1) = -1", output)
     driver.close()  # close the browser window
Beispiel #11
0
    def browserDriverExe(self, name):
        driver_version = 'unknown'
        driver_name = 'unknown'
        if name == 'safari':  ### Safari not working on Windows - need Safari 10 on OSX El Capitan
            safaridriver = self.driver_path
            driver = webdriver.Safari(safaridriver)
        elif name == "iexplorer" or name == "ie" or name == "IE":
            iedriverserver = self.driver_path
            driver = webdriver.Ie(iedriverserver)
        elif name == "firefox" or name == "ff":
            driver = webdriver.Firefox()
        elif name == 'brave':
            brave_exe = self.browser_exe
            chromedriverpath = self.driver_path
            chrome_options = webdriver.ChromeOptions()
            chrome_options.add_argument('--ignore-certificate-errors')
            chrome_options.add_argument("--disable-web-security")
            chrome_options.add_argument("--incognito")
            chrome_options.add_argument("--allow-running-insecure-content")
            chrome_options.add_argument("--allow-cross-origin-auth-prompt")
            chrome_options.add_argument("--disable-cookie-encryption")
            chrome_options.add_argument('--disable-dev-shm-usage')
            chrome_options.add_argument("--test-type")
            chrome_options.binary_location = brave_exe
            ## webdriver section
            driver = webdriver.Chrome(chromedriverpath, options=chrome_options)
            driver_name = 'brave'
        elif name == 'opera':
            from os import listdir
            from selenium.webdriver.common import desired_capabilities as operacapabilities
            from selenium.webdriver.opera import options as operaoptions
            _operaDriverLoc = self.driver_path
            # Opera browser
            _operaInstDir = self.browser_inst_dir
            listOperaDir = listdir(_operaInstDir)
            listOperaVer = [
                char for char in listOperaDir
                if char[0].isdigit() and char[-1].isdigit()
            ]
            # listOperaVer.sort(key=lambda version: [int(ver) for ver in version.split('.')])
            listOperaVer.sort()
            _operacurrentversion = listOperaVer[-1]
            _operaExeLoc = _operaInstDir + _operacurrentversion + r'\opera.exe'
            _operaCaps = operacapabilities.DesiredCapabilities.OPERA.copy()
            _operaOpts = operaoptions.ChromeOptions()
            _operaOpts._binary_location = _operaExeLoc
            driver = webdriver.Opera(executable_path=_operaDriverLoc,
                                     options=_operaOpts,
                                     desired_capabilities=_operaCaps)
            driver_name = 'opera'
            driver_version = _operacurrentversion
        elif name == "headless" or name == "nobrowser" or name == "virtual":
            # This is for running without open Browser UI display - good for Jenkins
            # # chrome_options.add_argument('--disable-extensions')
            # # chrome_options.add_argument("--disable-plugins-discovery")
            chromedriverpath = self.driver_path
            chrome_options = webdriver.ChromeOptions()
            chrome_options.add_argument('--headless')
            chrome_options.add_argument('--ignore-certificate-errors')
            chrome_options.add_argument("--disable-web-security")
            chrome_options.add_argument("--incognito")
            chrome_options.add_argument("--allow-running-insecure-content")
            chrome_options.add_argument("--allow-cross-origin-auth-prompt")
            chrome_options.add_argument("--disable-cookie-encryption")
            chrome_options.add_argument('--disable-dev-shm-usage')
            chrome_options.add_argument("--test-type")
            chrome_options.add_argument('--disable-default-apps')
            chrome_options.add_argument('--disable-prompt-on-repost')
            chrome_options.add_argument(
                "--disable-zero-browsers-open-for-tests")
            chrome_options.add_argument("--no-default-browser-check")
            chrome_options.add_argument("--proxy-server='direct://'")
            chrome_options.add_argument("--proxy-bypass-list=*")
            prefs = {"profile.default_content_setting_values.notifications": 2}
            chrome_options.add_experimental_option("prefs", prefs)
            driver = webdriver.Chrome(chromedriverpath, options=chrome_options)
        else:
            # Set chrome driver
            # name == "chrome":
            chromedriverpath = self.driver_path
            # for timebeing ONLY -- to ease OLD CODE
            if chromedriverpath == None:
                chromedriverpath = r'C:\tools\chromedriver\chromedriver.exe'
            #os.environ["webdriver.chrome.driver"] = chromedriverpath
            chrome_options = webdriver.ChromeOptions()
            #### headless - but not working at the moment
            # chrome_options.add_argument('--headless')
            # chrome_options.add_argument('--disable-gpu')
            # chrome_options.headless = True
            chrome_options.add_argument('--ignore-certificate-errors')
            chrome_options.add_argument("--disable-web-security")
            chrome_options.add_argument("--incognito")
            chrome_options.add_argument("--allow-running-insecure-content")
            chrome_options.add_argument("--allow-cross-origin-auth-prompt")
            chrome_options.add_argument("--disable-cookie-encryption")
            chrome_options.add_argument('--disable-dev-shm-usage')
            chrome_options.add_argument("--test-type")
            chrome_options.add_argument('--disable-default-apps')
            chrome_options.add_argument('--disable-prompt-on-repost')
            chrome_options.add_argument(
                "--disable-zero-browsers-open-for-tests")
            chrome_options.add_argument("--no-default-browser-check")
            prefs = {"profile.default_content_setting_values.notifications": 2}
            chrome_options.add_experimental_option("prefs", prefs)
            ## webdriver section
            driver = webdriver.Chrome(chromedriverpath, options=chrome_options)

        return driver, driver_name, driver_version
 def create_safari(self, desired_capabilities, remote_url):
     default = webdriver.DesiredCapabilities.SAFARI
     if is_truthy(remote_url):
         return self._remote(default, desired_capabilities, remote_url)
     capabilities = self._combine_capabilites(default, desired_capabilities)
     return webdriver.Safari(desired_capabilities=capabilities)
Beispiel #13
0
 def _safari(self, **kwargs):
     return webdriver.Safari(**kwargs)
        '//div[@class="_2S1VP copyable-text selectable-text"]')
    user.send_keys(sf_user)
    time.sleep(2)
    try:
        safarir = safari.find_element_by_xpath(
            '//span[@title="{}"]'.format(sf_user))
        safari.click()
    except NoSuchElementException:
        print('"{}" not found in contacts'.format(sf_user))
    except Exception as e:
        safari.close()
        print(e)
        sys.exit()


safari = webdriver.Safari(executable_path='/usr/bin/safaridriver')
safari.get('https://web.whatsapp.com')
print('Waiting...')
time.sleep(15)
try:
    sf_users = ['Test']
    for sf_user in sf_users:
        try:
            safari_user = safari.find_element_by_xpath(
                '//span[@title="{}"]'.format(sf_user))
            safari_user.click()
        except NoSuchElementException:
            newchatsafari(sf_user)
        safari_text = safari.find_element_by_xpath('//div[@class="_1Plpp"]')
        safari_text.send_keys('SPAMMING...')
        safari_send = safari.find_element_by_xpath('//button[@class="_35EW6"]')
Beispiel #15
0
def get_local_driver(browser_name, headless, servername, proxy_string,
                     proxy_auth, proxy_user, proxy_pass, user_agent,
                     disable_csp, enable_sync, use_auto_ext, no_sandbox,
                     disable_gpu, incognito, guest_mode, devtools, swiftshader,
                     block_images, user_data_dir, extension_zip, extension_dir,
                     mobile_emulator, device_width, device_height,
                     device_pixel_ratio):
    '''
    Spins up a new web browser and returns the driver.
    Can also be used to spin up additional browsers for the same test.
    '''
    downloads_path = download_helper.get_downloads_folder()
    download_helper.reset_downloads_folder()

    if browser_name == constants.Browser.FIREFOX:
        try:
            try:
                # Use Geckodriver for Firefox if it's on the PATH
                profile = _create_firefox_profile(downloads_path, proxy_string,
                                                  user_agent, disable_csp)
                firefox_capabilities = DesiredCapabilities.FIREFOX.copy()
                firefox_capabilities['marionette'] = True
                options = webdriver.FirefoxOptions()
                if headless:
                    options.add_argument('-headless')
                    firefox_capabilities['moz:firefoxOptions'] = ({
                        'args': ['-headless']
                    })
                if LOCAL_GECKODRIVER and os.path.exists(LOCAL_GECKODRIVER):
                    try:
                        make_driver_executable_if_not(LOCAL_GECKODRIVER)
                    except Exception as e:
                        logging.debug("\nWarning: Could not make geckodriver"
                                      " executable: %s" % e)
                elif not is_geckodriver_on_path():
                    args = " ".join(sys.argv)
                    if not ("-n" in sys.argv or "-n=" in args or args == "-c"):
                        # (Not multithreaded)
                        from seleniumbase.console_scripts import sb_install
                        sys_args = sys.argv  # Save a copy of current sys args
                        print("\nWarning: geckodriver not found!"
                              " Installing now:")
                        try:
                            sb_install.main(override="geckodriver")
                        except Exception as e:
                            print("\nWarning: Could not install geckodriver: "
                                  "%s" % e)
                        sys.argv = sys_args  # Put back the original sys args
                if "linux" in PLATFORM or not headless:
                    firefox_driver = webdriver.Firefox(
                        firefox_profile=profile,
                        capabilities=firefox_capabilities)
                else:
                    firefox_driver = webdriver.Firefox(
                        firefox_profile=profile,
                        capabilities=firefox_capabilities,
                        options=options)
            except Exception:
                profile = _create_firefox_profile(downloads_path, proxy_string,
                                                  user_agent, disable_csp)
                firefox_capabilities = DesiredCapabilities.FIREFOX.copy()
                firefox_driver = webdriver.Firefox(
                    firefox_profile=profile, capabilities=firefox_capabilities)
            return firefox_driver
        except Exception as e:
            if headless:
                raise Exception(e)
            return webdriver.Firefox()
    elif browser_name == constants.Browser.INTERNET_EXPLORER:
        if not IS_WINDOWS:
            raise Exception(
                "IE Browser is for Windows-based operating systems only!")
        from selenium.webdriver.ie.options import Options
        ie_options = Options()
        ie_options.ignore_protected_mode_settings = False
        ie_options.ignore_zoom_level = True
        ie_options.require_window_focus = False
        ie_options.native_events = True
        ie_options.full_page_screenshot = True
        ie_options.persistent_hover = True
        ie_capabilities = ie_options.to_capabilities()
        if LOCAL_IEDRIVER and os.path.exists(LOCAL_IEDRIVER):
            try:
                make_driver_executable_if_not(LOCAL_IEDRIVER)
            except Exception as e:
                logging.debug("\nWarning: Could not make iedriver"
                              " executable: %s" % e)
        return webdriver.Ie(capabilities=ie_capabilities)
    elif browser_name == constants.Browser.EDGE:
        try:
            chrome_options = _set_chrome_options(
                downloads_path, headless, proxy_string, proxy_auth, proxy_user,
                proxy_pass, user_agent, disable_csp, enable_sync, use_auto_ext,
                no_sandbox, disable_gpu, incognito, guest_mode, devtools,
                swiftshader, block_images, user_data_dir, extension_zip,
                extension_dir, servername, mobile_emulator, device_width,
                device_height, device_pixel_ratio)
            if LOCAL_EDGEDRIVER and os.path.exists(LOCAL_EDGEDRIVER):
                try:
                    make_driver_executable_if_not(LOCAL_EDGEDRIVER)
                except Exception as e:
                    logging.debug("\nWarning: Could not make edgedriver"
                                  " executable: %s" % e)
            elif not is_edgedriver_on_path():
                args = " ".join(sys.argv)
                if not ("-n" in sys.argv or "-n=" in args or args == "-c"):
                    # (Not multithreaded)
                    from seleniumbase.console_scripts import sb_install
                    sys_args = sys.argv  # Save a copy of current sys args
                    print("\nWarning: msedgedriver not found. Installing now:")
                    sb_install.main(override="edgedriver")
                    sys.argv = sys_args  # Put back the original sys args
            return webdriver.Chrome(executable_path=LOCAL_EDGEDRIVER,
                                    options=chrome_options)
        except Exception as e:
            if headless:
                raise Exception(e)
            if LOCAL_EDGEDRIVER and os.path.exists(LOCAL_EDGEDRIVER):
                try:
                    make_driver_executable_if_not(LOCAL_EDGEDRIVER)
                except Exception as e:
                    logging.debug("\nWarning: Could not make edgedriver"
                                  " executable: %s" % e)
            return webdriver.Chrome(executable_path=LOCAL_EDGEDRIVER)
    elif browser_name == constants.Browser.SAFARI:
        arg_join = " ".join(sys.argv)
        if ("-n" in sys.argv) or ("-n=" in arg_join) or (arg_join == "-c"):
            # Skip if multithreaded
            raise Exception("Can't run Safari tests in multi-threaded mode!")
        safari_capabilities = _set_safari_capabilities()
        return webdriver.Safari(desired_capabilities=safari_capabilities)
    elif browser_name == constants.Browser.OPERA:
        if LOCAL_OPERADRIVER and os.path.exists(LOCAL_OPERADRIVER):
            try:
                make_driver_executable_if_not(LOCAL_OPERADRIVER)
            except Exception as e:
                logging.debug("\nWarning: Could not make operadriver"
                              " executable: %s" % e)
        return webdriver.Opera()
    elif browser_name == constants.Browser.PHANTOM_JS:
        with warnings.catch_warnings():
            # Ignore "PhantomJS has been deprecated" UserWarning
            warnings.simplefilter("ignore", category=UserWarning)
            return webdriver.PhantomJS()
    elif browser_name == constants.Browser.GOOGLE_CHROME:
        try:
            chrome_options = _set_chrome_options(
                downloads_path, headless, proxy_string, proxy_auth, proxy_user,
                proxy_pass, user_agent, disable_csp, enable_sync, use_auto_ext,
                no_sandbox, disable_gpu, incognito, guest_mode, devtools,
                swiftshader, block_images, user_data_dir, extension_zip,
                extension_dir, servername, mobile_emulator, device_width,
                device_height, device_pixel_ratio)
            if LOCAL_CHROMEDRIVER and os.path.exists(LOCAL_CHROMEDRIVER):
                try:
                    make_driver_executable_if_not(LOCAL_CHROMEDRIVER)
                except Exception as e:
                    logging.debug("\nWarning: Could not make chromedriver"
                                  " executable: %s" % e)
            elif not is_chromedriver_on_path():
                args = " ".join(sys.argv)
                if not ("-n" in sys.argv or "-n=" in args or args == "-c"):
                    # (Not multithreaded)
                    from seleniumbase.console_scripts import sb_install
                    sys_args = sys.argv  # Save a copy of current sys args
                    print("\nWarning: chromedriver not found. Installing now:")
                    sb_install.main(override="chromedriver")
                    sys.argv = sys_args  # Put back the original sys args
            if not headless or "linux" not in PLATFORM:
                return webdriver.Chrome(options=chrome_options)
            else:  # Running headless on Linux
                try:
                    return webdriver.Chrome(options=chrome_options)
                except Exception:
                    # Use the virtual display on Linux during headless errors
                    logging.debug("\nWarning: Chrome failed to launch in"
                                  " headless mode. Attempting to use the"
                                  " SeleniumBase virtual display on Linux...")
                    chrome_options.headless = False
                    return webdriver.Chrome(options=chrome_options)
        except Exception as e:
            if headless:
                raise Exception(e)
            if LOCAL_CHROMEDRIVER and os.path.exists(LOCAL_CHROMEDRIVER):
                try:
                    make_driver_executable_if_not(LOCAL_CHROMEDRIVER)
                except Exception as e:
                    logging.debug("\nWarning: Could not make chromedriver"
                                  " executable: %s" % e)
            return webdriver.Chrome()
    else:
        raise Exception("%s is not a valid browser option for this system!" %
                        browser_name)
Beispiel #16
0
def get_local_driver(
        browser_name, headless, servername,
        proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
        disable_csp, enable_sync, user_data_dir,
        extension_zip, extension_dir,
        mobile_emulator, device_width, device_height, device_pixel_ratio):
    '''
    Spins up a new web browser and returns the driver.
    Can also be used to spin up additional browsers for the same test.
    '''
    downloads_path = download_helper.get_downloads_folder()
    download_helper.reset_downloads_folder()

    if browser_name == constants.Browser.FIREFOX:
        try:
            try:
                # Use Geckodriver for Firefox if it's on the PATH
                profile = _create_firefox_profile(
                    downloads_path, proxy_string, user_agent, disable_csp)
                firefox_capabilities = DesiredCapabilities.FIREFOX.copy()
                firefox_capabilities['marionette'] = True
                options = webdriver.FirefoxOptions()
                if headless:
                    options.add_argument('-headless')
                if LOCAL_GECKODRIVER and os.path.exists(LOCAL_GECKODRIVER):
                    make_driver_executable_if_not(LOCAL_GECKODRIVER)
                elif not is_geckodriver_on_path():
                    if not "".join(sys.argv) == "-c":  # Skip if multithreaded
                        from seleniumbase.console_scripts import sb_install
                        sys_args = sys.argv  # Save a copy of current sys args
                        print("\nWarning: geckodriver not found."
                              " Installing now:")
                        sb_install.main(override="geckodriver")
                        sys.argv = sys_args  # Put back the original sys args
                firefox_driver = webdriver.Firefox(
                    firefox_profile=profile,
                    capabilities=firefox_capabilities,
                    options=options)
            except WebDriverException:
                # Don't use Geckodriver: Only works for old versions of Firefox
                profile = _create_firefox_profile(
                    downloads_path, proxy_string, user_agent, disable_csp)
                firefox_capabilities = DesiredCapabilities.FIREFOX.copy()
                firefox_capabilities['marionette'] = False
                firefox_driver = webdriver.Firefox(
                    firefox_profile=profile, capabilities=firefox_capabilities)
            return firefox_driver
        except Exception as e:
            if headless:
                raise Exception(e)
            return webdriver.Firefox()
    elif browser_name == constants.Browser.INTERNET_EXPLORER:
        if not IS_WINDOWS:
            raise Exception(
                "IE Browser is for Windows-based operating systems only!")
        from selenium.webdriver.ie.options import Options
        ie_options = Options()
        ie_options.ignore_protected_mode_settings = False
        ie_options.ignore_zoom_level = True
        ie_options.require_window_focus = False
        ie_options.native_events = True
        ie_options.full_page_screenshot = True
        ie_options.persistent_hover = True
        ie_capabilities = ie_options.to_capabilities()
        if LOCAL_IEDRIVER and os.path.exists(LOCAL_IEDRIVER):
            make_driver_executable_if_not(LOCAL_IEDRIVER)
        return webdriver.Ie(capabilities=ie_capabilities)
    elif browser_name == constants.Browser.EDGE:
        if LOCAL_EDGEDRIVER and os.path.exists(LOCAL_EDGEDRIVER):
            make_driver_executable_if_not(LOCAL_EDGEDRIVER)
            # The new Microsoft Edge browser is based on Chromium
            chrome_options = _set_chrome_options(
                downloads_path, headless,
                proxy_string, proxy_auth, proxy_user, proxy_pass,
                user_agent, disable_csp, enable_sync, user_data_dir,
                extension_zip, extension_dir, servername, mobile_emulator,
                device_width, device_height, device_pixel_ratio)
            return webdriver.Chrome(executable_path=LOCAL_EDGEDRIVER,
                                    options=chrome_options)
        else:
            return webdriver.Edge()
    elif browser_name == constants.Browser.SAFARI:
        if "".join(sys.argv) == "-c":  # Skip if multithreaded
            raise Exception("Can't run Safari tests in multi-threaded mode!")
        return webdriver.Safari()
    elif browser_name == constants.Browser.OPERA:
        if LOCAL_OPERADRIVER and os.path.exists(LOCAL_OPERADRIVER):
            make_driver_executable_if_not(LOCAL_OPERADRIVER)
        return webdriver.Opera()
    elif browser_name == constants.Browser.PHANTOM_JS:
        with warnings.catch_warnings():
            # Ignore "PhantomJS has been deprecated" UserWarning
            warnings.simplefilter("ignore", category=UserWarning)
            return webdriver.PhantomJS()
    elif browser_name == constants.Browser.GOOGLE_CHROME:
        try:
            chrome_options = _set_chrome_options(
                downloads_path, headless,
                proxy_string, proxy_auth, proxy_user, proxy_pass,
                user_agent, disable_csp, enable_sync, user_data_dir,
                extension_zip, extension_dir, servername, mobile_emulator,
                device_width, device_height, device_pixel_ratio)
            if LOCAL_CHROMEDRIVER and os.path.exists(LOCAL_CHROMEDRIVER):
                make_driver_executable_if_not(LOCAL_CHROMEDRIVER)
            elif not is_chromedriver_on_path():
                if not "".join(sys.argv) == "-c":  # Skip if multithreaded
                    from seleniumbase.console_scripts import sb_install
                    sys_args = sys.argv  # Save a copy of current sys args
                    print("\nWarning: chromedriver not found. Installing now:")
                    sb_install.main(override="chromedriver")
                    sys.argv = sys_args  # Put back the original sys args
            return webdriver.Chrome(options=chrome_options)
        except Exception as e:
            if headless:
                raise Exception(e)
            if LOCAL_CHROMEDRIVER and os.path.exists(LOCAL_CHROMEDRIVER):
                make_driver_executable_if_not(LOCAL_CHROMEDRIVER)
            return webdriver.Chrome()
    else:
        raise Exception(
            "%s is not a valid browser option for this system!" % browser_name)
Beispiel #17
0
 def safari():
     if SafariConfig.command_executor != "":
         return webdriver.Remote(
             command_executor=SafariConfig.command_executor,
             desired_capabilities=DesiredCapabilities.SAFARI.copy())
     return webdriver.Safari(executable_path=SafariConfig.executable_path)
def _environment_config(context):
    """
    For setting up automation environment to be used for test execution.
    :param context: Behave object holder variable
    :return: none
    """
    logging.info("")
    logging.info(" <<<<<<<<<<< SETTING UP AUTOMATION ENVIRONMENT >>>>>>>>>>>>>")
    device_stack = context.env_var.get("DEVICE")
    logging.info(" * - Setting up the device platform - {}".format(device_stack))
    logging.info(" * - Setting up the web driver instance")

    # Setting up the driver executable based on OS running
    # exe_path = "drivers/mac/chromedriver" if 'Darwin'in str(platform.platform()) else "drivers/chromedriver"
    exe_path = "drivers/chromedriver"

    if device_stack == "Mobile":
        logging.info(" * - Mobile emulator - Pixel 2")
        # Define mobile emulator model
        mobile_emulation = {"deviceName": "Pixel 2"}
        # Define a variable to hold all the configurations we want
        chrome_options = webdriver.ChromeOptions()
        # Add the mobile emulation to the chrome options variable
        chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
        # Create driver, pass it the path to the chromedriver file and the special configurations you want to run
        logging.info(" * - Setting up chrome for mobile environment")
        try:
            context.driver = webdriver.Chrome(
                executable_path="drivers/chromedriver",
                options=chrome_options)
        except Exception:
            logging.info(" * - < ..... Exception : unable to config chrome driver ")
            logging.info(" * - <.....> - {}".format(sys.exc_info()[1]))
            assert False, "Issue in Chrome driver"

    elif device_stack == "Website":
        # Browser driver configuration
        browser_stack = context.env_var.get("BROWSER").upper()
        logging.info(" * - BROWSER DEFINED : {}".format(browser_stack))

        if browser_stack == "GC" or browser_stack == "GOOGLECHROME" or browser_stack == "CHROME":
            logging.info(" * - Configuring Google Chrome driver ")
            try:
                #context.driver = webdriver.Chrome(executable_path="drivers/chromedriver")
                chrome_options = webdriver.ChromeOptions()
                chrome_options.add_argument('--no-sandbox')
                #chrome_options.add_argument('--headless')
                chrome_options.add_argument('--disable-gpu')
                #chrome_options.add_argument('--dns-prefetch-disable')
                #chrome_options.add_argument("--disable-extensions")
                #chrome_options.add_argument("--disable-dev-shm-usage")
                WINDOW_SIZE = "1440,900" # standard size of windows
                IPAD_PRO_SIZE = "1024,1366"
                IPAD = "768,1024"
                IPHONE678 = "375,667"
                chrome_options.add_argument("--window-size=%s" % WINDOW_SIZE)
                #capabilities = chrome_options.to_capabilities()
                context.driver = webdriver.Chrome(chrome_options=chrome_options)
                #context.driver = webdriver.Chrome(executable_path="drivers/chromedriver", options=chrome_options)
                #context.driver.set_page_load_timeout(30)
            except Exception:
                logging.info(" * - < ..... Exception : unable to config chrome driver ")
                logging.info(" * - <.....> - {}".format(sys.exc_info()[1]))
                assert False, "Issue in Chrome driver"
        elif browser_stack == "FF" or browser_stack == "FIREFOX" or browser_stack == "MORZILLAFIREFOX":
            logging.info(" * - Configuring Firefox driver .")
            caps = DesiredCapabilities.FIREFOX
            #caps["pageLoadStrategy"] = "normal"  # complete
            caps["pageLoadStrategy"] = "eager"  #  interactive
            #caps["pageLoadStrategy"] = "none"
            try:
                context.driver = webdriver.Firefox(capabilities=caps)
            except Exception:
                logging.info(" * - < ..... Exception : unable to config Firefox driver ")
                logging.info("<.....> - {}".format(sys.exc_info()[1]))
                assert False , "Issue in firefox driver"
        elif browser_stack == "SAFARI":
            try:
                logging.info(" * - Configuring Safari driver .")
                context.driver = webdriver.Safari()
            except Exception:
                logging.info(" * - < ..... Exception : unable to config safari driver ")
                logging.info("<.....> - {}".format(sys.exc_info()[1]))
                assert False, "Issue in chrome driver"

    else:
        logging.info(" * - Configuring Firefox driver ")
        caps = DesiredCapabilities.FIREFOX
        # caps["pageLoadStrategy"] = "normal"  # complete
        caps["pageLoadStrategy"] = "eager"  # interactive
        # caps["pageLoadStrategy"] = "none"
        try:
            context.driver = webdriver.Firefox(capabilities=caps)
        except Exception:
            logging.info(" * - < ..... Exception : unable to config Firefox driver ")
            logging.info("<.....> - {}".format(sys.exc_info()[1]))
            assert False, "Issue in firefox driver"
def get_local_driver(
        browser_name, headless, locale_code, servername,
        proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
        disable_csp, enable_ws, enable_sync, use_auto_ext, no_sandbox,
        disable_gpu, incognito, guest_mode, devtools, swiftshader,
        block_images, user_data_dir, extension_zip, extension_dir,
        mobile_emulator, device_width, device_height, device_pixel_ratio):
    '''
    Spins up a new web browser and returns the driver.
    Can also be used to spin up additional browsers for the same test.
    '''
    downloads_path = download_helper.get_downloads_folder()
    download_helper.reset_downloads_folder()

    if browser_name == constants.Browser.FIREFOX:
        try:
            try:
                # Use Geckodriver for Firefox if it's on the PATH
                profile = _create_firefox_profile(
                    downloads_path, locale_code,
                    proxy_string, user_agent, disable_csp)
                firefox_capabilities = DesiredCapabilities.FIREFOX.copy()
                firefox_capabilities['marionette'] = True
                options = webdriver.FirefoxOptions()
                if headless:
                    options.add_argument('-headless')
                    firefox_capabilities['moz:firefoxOptions'] = (
                        {'args': ['-headless']})
                if LOCAL_GECKODRIVER and os.path.exists(LOCAL_GECKODRIVER):
                    try:
                        make_driver_executable_if_not(LOCAL_GECKODRIVER)
                    except Exception as e:
                        logging.debug("\nWarning: Could not make geckodriver"
                                      " executable: %s" % e)
                elif not is_geckodriver_on_path():
                    args = " ".join(sys.argv)
                    if not ("-n" in sys.argv or "-n=" in args or args == "-c"):
                        # (Not multithreaded)
                        from seleniumbase.console_scripts import sb_install
                        sys_args = sys.argv  # Save a copy of current sys args
                        print("\nWarning: geckodriver not found!"
                              " Installing now:")
                        try:
                            sb_install.main(override="geckodriver")
                        except Exception as e:
                            print("\nWarning: Could not install geckodriver: "
                                  "%s" % e)
                        sys.argv = sys_args  # Put back the original sys args
                if "linux" in PLATFORM or not headless:
                    firefox_driver = webdriver.Firefox(
                        firefox_profile=profile,
                        capabilities=firefox_capabilities)
                else:
                    firefox_driver = webdriver.Firefox(
                        firefox_profile=profile,
                        capabilities=firefox_capabilities,
                        options=options)
            except Exception:
                profile = _create_firefox_profile(
                    downloads_path, locale_code,
                    proxy_string, user_agent, disable_csp)
                firefox_capabilities = DesiredCapabilities.FIREFOX.copy()
                firefox_driver = webdriver.Firefox(
                    firefox_profile=profile,
                    capabilities=firefox_capabilities)
            return firefox_driver
        except Exception as e:
            if headless:
                raise Exception(e)
            return webdriver.Firefox()
    elif browser_name == constants.Browser.INTERNET_EXPLORER:
        if not IS_WINDOWS:
            raise Exception(
                "IE Browser is for Windows-based operating systems only!")
        from selenium.webdriver.ie.options import Options
        ie_options = Options()
        ie_options.ignore_protected_mode_settings = False
        ie_options.ignore_zoom_level = True
        ie_options.require_window_focus = False
        ie_options.native_events = True
        ie_options.full_page_screenshot = True
        ie_options.persistent_hover = True
        ie_capabilities = ie_options.to_capabilities()
        if LOCAL_IEDRIVER and os.path.exists(LOCAL_IEDRIVER):
            try:
                make_driver_executable_if_not(LOCAL_IEDRIVER)
            except Exception as e:
                logging.debug("\nWarning: Could not make iedriver"
                              " executable: %s" % e)
        return webdriver.Ie(capabilities=ie_capabilities)
    elif browser_name == constants.Browser.EDGE:
        try:
            chrome_options = _set_chrome_options(
                browser_name, downloads_path, headless, locale_code,
                proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
                disable_csp, enable_ws, enable_sync, use_auto_ext,
                no_sandbox, disable_gpu, incognito, guest_mode, devtools,
                swiftshader, block_images, user_data_dir,
                extension_zip, extension_dir, servername,
                mobile_emulator, device_width, device_height,
                device_pixel_ratio)
            if LOCAL_EDGEDRIVER and os.path.exists(LOCAL_EDGEDRIVER):
                try:
                    make_driver_executable_if_not(LOCAL_EDGEDRIVER)
                except Exception as e:
                    logging.debug("\nWarning: Could not make edgedriver"
                                  " executable: %s" % e)
            elif not is_edgedriver_on_path():
                args = " ".join(sys.argv)
                if not ("-n" in sys.argv or "-n=" in args or args == "-c"):
                    # (Not multithreaded)
                    from seleniumbase.console_scripts import sb_install
                    sys_args = sys.argv  # Save a copy of current sys args
                    print("\nWarning: msedgedriver not found. Installing now:")
                    sb_install.main(override="edgedriver")
                    sys.argv = sys_args  # Put back the original sys args
            # For Microsoft Edge (Chromium) version 79 or lower
            return webdriver.Chrome(executable_path=LOCAL_EDGEDRIVER,
                                    options=chrome_options)
        except Exception:
            # For Microsoft Edge (Chromium) version 80 or higher
            from msedge.selenium_tools import Edge, EdgeOptions
            if LOCAL_EDGEDRIVER and os.path.exists(LOCAL_EDGEDRIVER):
                try:
                    make_driver_executable_if_not(LOCAL_EDGEDRIVER)
                except Exception as e:
                    logging.debug("\nWarning: Could not make edgedriver"
                                  " executable: %s" % e)
            edge_options = EdgeOptions()
            edge_options.use_chromium = True
            prefs = {
                "download.default_directory": downloads_path,
                "local_discovery.notifications_enabled": False,
                "credentials_enable_service": False,
                "download.prompt_for_download": False,
                "download.directory_upgrade": True,
                "safebrowsing.enabled": False,
                "safebrowsing.disable_download_protection": True,
                "profile": {
                    "password_manager_enabled": False
                }
            }
            if locale_code:
                prefs["intl.accept_languages"] = locale_code
            if block_images:
                prefs["profile.managed_default_content_settings.images"] = 2
            edge_options.add_experimental_option("prefs", prefs)
            edge_options.add_experimental_option("w3c", True)
            edge_options.add_experimental_option(
                "useAutomationExtension", False)
            edge_options.add_experimental_option(
                "excludeSwitches", ["enable-automation", "enable-logging"])
            if guest_mode:
                edge_options.add_argument("--guest")
            if headless:
                edge_options.add_argument("--headless")
            if mobile_emulator:
                emulator_settings = {}
                device_metrics = {}
                if type(device_width) is int and (
                        type(device_height) is int and (
                        type(device_pixel_ratio) is int)):
                    device_metrics["width"] = device_width
                    device_metrics["height"] = device_height
                    device_metrics["pixelRatio"] = device_pixel_ratio
                else:
                    device_metrics["width"] = 411
                    device_metrics["height"] = 731
                    device_metrics["pixelRatio"] = 3
                emulator_settings["deviceMetrics"] = device_metrics
                if user_agent:
                    emulator_settings["userAgent"] = user_agent
                edge_options.add_experimental_option(
                    "mobileEmulation", emulator_settings)
                edge_options.add_argument("--enable-sync")
            edge_options.add_argument("--disable-infobars")
            edge_options.add_argument("--disable-save-password-bubble")
            edge_options.add_argument("--disable-single-click-autofill")
            edge_options.add_argument("--disable-translate")
            if not enable_ws:
                edge_options.add_argument("--disable-web-security")
            edge_options.add_argument("--homepage=about:blank")
            edge_options.add_argument("--dns-prefetch-disable")
            edge_options.add_argument("--dom-automation")
            edge_options.add_argument("--disable-hang-monitor")
            edge_options.add_argument("--disable-prompt-on-repost")
            if proxy_string:
                edge_options.add_argument('--proxy-server=%s' % proxy_string)
            edge_options.add_argument("--test-type")
            edge_options.add_argument("--log-level=3")
            edge_options.add_argument("--no-first-run")
            edge_options.add_argument("--ignore-certificate-errors")
            if devtools and not headless:
                edge_options.add_argument("--auto-open-devtools-for-tabs")
            edge_options.add_argument("--allow-file-access-from-files")
            edge_options.add_argument("--allow-insecure-localhost")
            edge_options.add_argument("--allow-running-insecure-content")
            if user_agent:
                edge_options.add_argument("--user-agent=%s" % user_agent)
            edge_options.add_argument("--no-sandbox")
            if swiftshader:
                edge_options.add_argument("--use-gl=swiftshader")
            else:
                edge_options.add_argument("--disable-gpu")
            if "linux" in PLATFORM:
                edge_options.add_argument("--disable-dev-shm-usage")
            capabilities = edge_options.to_capabilities()
            capabilities["platform"] = ''
            return Edge(
                executable_path=LOCAL_EDGEDRIVER, capabilities=capabilities)
    elif browser_name == constants.Browser.SAFARI:
        arg_join = " ".join(sys.argv)
        if ("-n" in sys.argv) or ("-n=" in arg_join) or (arg_join == "-c"):
            # Skip if multithreaded
            raise Exception("Can't run Safari tests in multi-threaded mode!")
        safari_capabilities = _set_safari_capabilities()
        return webdriver.Safari(desired_capabilities=safari_capabilities)
    elif browser_name == constants.Browser.OPERA:
        try:
            if LOCAL_OPERADRIVER and os.path.exists(LOCAL_OPERADRIVER):
                try:
                    make_driver_executable_if_not(LOCAL_OPERADRIVER)
                except Exception as e:
                    logging.debug("\nWarning: Could not make operadriver"
                                  " executable: %s" % e)
            opera_options = _set_chrome_options(
                browser_name, downloads_path, headless, locale_code,
                proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
                disable_csp, enable_ws, enable_sync, use_auto_ext,
                no_sandbox, disable_gpu, incognito, guest_mode, devtools,
                swiftshader, block_images, user_data_dir, extension_zip,
                extension_dir, servername, mobile_emulator,
                device_width, device_height, device_pixel_ratio)
            opera_options.headless = False  # No support for headless Opera
            return webdriver.Opera(options=opera_options)
        except Exception:
            return webdriver.Opera()
    elif browser_name == constants.Browser.PHANTOM_JS:
        with warnings.catch_warnings():
            # Ignore "PhantomJS has been deprecated" UserWarning
            warnings.simplefilter("ignore", category=UserWarning)
            return webdriver.PhantomJS()
    elif browser_name == constants.Browser.GOOGLE_CHROME:
        try:
            chrome_options = _set_chrome_options(
                browser_name, downloads_path, headless, locale_code,
                proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent,
                disable_csp, enable_ws, enable_sync, use_auto_ext,
                no_sandbox, disable_gpu, incognito, guest_mode, devtools,
                swiftshader, block_images, user_data_dir, extension_zip,
                extension_dir, servername, mobile_emulator,
                device_width, device_height, device_pixel_ratio)
            if LOCAL_CHROMEDRIVER and os.path.exists(LOCAL_CHROMEDRIVER):
                try:
                    make_driver_executable_if_not(LOCAL_CHROMEDRIVER)
                except Exception as e:
                    logging.debug("\nWarning: Could not make chromedriver"
                                  " executable: %s" % e)
            elif not is_chromedriver_on_path():
                args = " ".join(sys.argv)
                if not ("-n" in sys.argv or "-n=" in args or args == "-c"):
                    # (Not multithreaded)
                    from seleniumbase.console_scripts import sb_install
                    sys_args = sys.argv  # Save a copy of current sys args
                    print("\nWarning: chromedriver not found. Installing now:")
                    sb_install.main(override="chromedriver")
                    sys.argv = sys_args  # Put back the original sys args
            if not headless or "linux" not in PLATFORM:
                return webdriver.Chrome(options=chrome_options)
            else:  # Running headless on Linux
                try:
                    return webdriver.Chrome(options=chrome_options)
                except Exception:
                    # Use the virtual display on Linux during headless errors
                    logging.debug("\nWarning: Chrome failed to launch in"
                                  " headless mode. Attempting to use the"
                                  " SeleniumBase virtual display on Linux...")
                    chrome_options.headless = False
                    return webdriver.Chrome(options=chrome_options)
        except Exception as e:
            if headless:
                raise Exception(e)
            if LOCAL_CHROMEDRIVER and os.path.exists(LOCAL_CHROMEDRIVER):
                try:
                    make_driver_executable_if_not(LOCAL_CHROMEDRIVER)
                except Exception as e:
                    logging.debug("\nWarning: Could not make chromedriver"
                                  " executable: %s" % e)
            return webdriver.Chrome()
    else:
        raise Exception(
            "%s is not a valid browser option for this system!" % browser_name)
Beispiel #20
0
 def __init__(self):
     self.driver = webdriver.Safari()
     self.USER = config('GIT_USER')
     self.PASSWORD = config('GIT_PASSWORD')
     self.PROJECT_NAME = sys.argv[1]
     self.TOKEN=config('TOKEN')
def get_info(item, brow, f_name, f_path):
    res_lis = []
    if (f_name == '0'):
        path = f_path
    else:
        path = '/Users/' + f_name + '/Downloads'
    if (brow == 1):
        path = path + '/chromedriver'
        driver = webdriver.Chrome(path)
    if (brow == 2):
        path = path + '/firefoxdriver'
        driver = webdriver.Firefox(path)
    if (brow == 3):
        path = path + '/iexplorerdriver'
        driver = webdriver.Edge(path)
    if (brow == 4):
        path = path + '/operadriver'
        driver = webdriver.Opera(path)
    if (brow == 5):
        path = path + '/safaridriver'
        driver = webdriver.Safari(path)

    item = item.encode('unicode_escape')
    item = str(item)[2:-1].replace('\\\\', '%')

    driver.get('http://corners.auction.co.kr/corner/UsedMarketList.aspx' +
               '?keyword=' + item)
    html = driver.page_source
    try:  #'더 보기'가 있다면 모든 '더 보기' 클릭
        bsobj = BeautifulSoup(html, 'html.parser')
        page = bsobj.find('div', {'class': 'page'}).text
        page_number = page.split('/')
        page_max = page_number[1]
        for i in range(1, int(page_max)):
            time.sleep(1)
            driver.find_element_by_css_selector(
                '#ucPager_dListMoreView > a').click()
    except:
        pass
    html = driver.page_source
    bsobj = BeautifulSoup(html, 'html.parser')
    divs = bsobj.find_all('div', {'class': 'list_view'})
    for div in divs:  #제목, 가격, 배송비, url 뽑기
        div_item = div.find('div', {'class': 'item_title type1'})
        title = div_item.find('a').text
        url_item = div_item.find('a')['href']
        span = div.find('span', {'class': 'now'})
        price = span.find('strong').text
        try:
            del_fee = div.find('div', {'class': 'icon ic_delivery'}).text
        except:
            del_fee = '무료 배송'
        a_link = div.find('a')['href']
        num_of_pagedowns = 5
        driver.get(a_link)
        body = driver.find_element_by_tag_name('body')
        while num_of_pagedowns:  #스크롤이 내려간 이벤트 후, 정보가 불러와지기 때문에 스크롤을 내림
            body.send_keys(Keys.PAGE_DOWN)
            time.sleep(0.1)
            num_of_pagedowns -= 1
        html = driver.page_source
        bsobj = BeautifulSoup(html, 'html.parser')
        try:
            div_date = bsobj.find('div', {'class': 'seller_update'})
            date = div_date.find('span', {
                'id': 'spanNewDescriptionLastUpdate'
            }).text
        except:
            date = 'NONE'
        res_lis.append({
            'title': title,
            'price': price,
            'delivery fee': del_fee,
            'url': url_item,
            'date': date
        })
    jangteor = pd.DataFrame(res_lis)
    jangteor.to_csv('jangteor_crawling.csv', mode='w', index=False)
Beispiel #22
0
    def setUp(self):
        """Setup the test"""
        # Web Browser Instance
        self.driver = webdriver.Safari()
        self.driver.get("http://127.0.0.1:8000/")

        # Setup game players
        player_list = self.driver.find_element_by_name('playerList')
        player_list.click()
        player_list.send_keys(Keys.COMMAND + "a")
        player_list.send_keys(Keys.DELETE)
        player_list.send_keys("ID1,ID2")

        # Choose difficulty
        difficulty_levels = Select(self.driver.find_element_by_name('level'))
        difficulty_levels.select_by_visible_text('Easy')

        # Start Game
        self.driver.find_element_by_name('start_game').click()

        # Let game load
        sleep(5)

        # Collect the displayed player information
        players_obj = self.driver.find_elements_by_name("player_name_display")
        player_points_obj = self.driver.find_elements_by_name(
            "player_points_display")
        player_cards_obj = self.driver.find_elements_by_name(
            "player_cards_display")
        deck_size_obj = self.driver.find_element_by_id("deck_size_display")

        # extract text
        self.players = list()
        self.points = list()
        self.cards = list()
        self.turn = ''
        self.deck_size = deck_size_obj.text.split(':')[1].strip()

        for index, instance in enumerate(players_obj):

            if '*' in instance.text:
                self.turn = instance.text.replace('*', '').strip()

            self.players.append(instance.text.replace('*', '').strip())
            self.points.append(player_points_obj[index].text.strip())
            self.cards.append(player_cards_obj[index].text.split('-'))

        # Get cookies
        cookies = self.driver.get_cookies()
        game_id = ""
        for cookie in cookies:
            if cookie['name'] == 'game_id':
                game_id = cookie['value']

        # Pull the expected game from API
        url = 'http://127.0.0.1:8000/game_board/api/board/' + game_id
        response = requests.get(url)
        board = json.loads(response.text)
        self.check_turn = board['turn']
        self.check_points = board['player_points']
        self.check_cards = board['cards']
        self.check_deck_size = len(board['deck'])

        # End the test. Closes the browser.
        self.driver.close()
def open_browser():
    browser = webdriver.Safari()
    return browser
def get_local_driver(browser_name, headless, proxy_string, proxy_auth,
                     proxy_user, proxy_pass, user_agent, disable_csp,
                     enable_sync, user_data_dir, extension_zip, extension_dir):
    '''
    Spins up a new web browser and returns the driver.
    Can also be used to spin up additional browsers for the same test.
    '''
    downloads_path = download_helper.get_downloads_folder()
    download_helper.reset_downloads_folder()

    if browser_name == constants.Browser.FIREFOX:
        try:
            try:
                # Use Geckodriver for Firefox if it's on the PATH
                profile = _create_firefox_profile(downloads_path, proxy_string,
                                                  user_agent, disable_csp)
                firefox_capabilities = DesiredCapabilities.FIREFOX.copy()
                firefox_capabilities['marionette'] = True
                options = webdriver.FirefoxOptions()
                if headless:
                    options.add_argument('-headless')
                if LOCAL_GECKODRIVER and os.path.exists(LOCAL_GECKODRIVER):
                    make_driver_executable_if_not(LOCAL_GECKODRIVER)
                    firefox_driver = webdriver.Firefox(
                        firefox_profile=profile,
                        capabilities=firefox_capabilities,
                        options=options,
                        executable_path=LOCAL_GECKODRIVER)
                else:
                    firefox_driver = webdriver.Firefox(
                        firefox_profile=profile,
                        capabilities=firefox_capabilities,
                        options=options)
            except WebDriverException:
                # Don't use Geckodriver: Only works for old versions of Firefox
                profile = _create_firefox_profile(downloads_path, proxy_string,
                                                  user_agent, disable_csp)
                firefox_capabilities = DesiredCapabilities.FIREFOX.copy()
                firefox_capabilities['marionette'] = False
                firefox_driver = webdriver.Firefox(
                    firefox_profile=profile, capabilities=firefox_capabilities)
            return firefox_driver
        except Exception as e:
            if headless:
                raise Exception(e)
            return webdriver.Firefox()
    elif browser_name == constants.Browser.INTERNET_EXPLORER:
        if not IS_WINDOWS:
            raise Exception(
                "IE Browser is for Windows-based operating systems only!")
        from selenium.webdriver.ie.options import Options
        ie_options = Options()
        ie_options.ignore_protected_mode_settings = False
        ie_options.ignore_zoom_level = True
        ie_options.require_window_focus = False
        ie_options.native_events = True
        ie_options.full_page_screenshot = True
        ie_options.persistent_hover = True
        ie_capabilities = ie_options.to_capabilities()
        if LOCAL_IEDRIVER and os.path.exists(LOCAL_IEDRIVER):
            make_driver_executable_if_not(LOCAL_IEDRIVER)
            return webdriver.Ie(capabilities=ie_capabilities,
                                executable_path=LOCAL_IEDRIVER)
        else:
            return webdriver.Ie(capabilities=ie_capabilities)
    elif browser_name == constants.Browser.EDGE:
        if not IS_WINDOWS:
            raise Exception(
                "Edge Browser is for Windows-based operating systems only!")
        edge_capabilities = DesiredCapabilities.EDGE.copy()
        if LOCAL_EDGEDRIVER and os.path.exists(LOCAL_EDGEDRIVER):
            make_driver_executable_if_not(LOCAL_EDGEDRIVER)
            return webdriver.Edge(capabilities=edge_capabilities,
                                  executable_path=LOCAL_EDGEDRIVER)
        else:
            return webdriver.Edge(capabilities=edge_capabilities)
    elif browser_name == constants.Browser.SAFARI:
        return webdriver.Safari()
    elif browser_name == constants.Browser.OPERA:
        if LOCAL_OPERADRIVER and os.path.exists(LOCAL_OPERADRIVER):
            make_driver_executable_if_not(LOCAL_OPERADRIVER)
            return webdriver.Opera(executable_path=LOCAL_OPERADRIVER)
        else:
            return webdriver.Opera()
    elif browser_name == constants.Browser.PHANTOM_JS:
        with warnings.catch_warnings():
            # Ignore "PhantomJS has been deprecated" UserWarning
            warnings.simplefilter("ignore", category=UserWarning)
            return webdriver.PhantomJS()
    elif browser_name == constants.Browser.GOOGLE_CHROME:
        try:
            chrome_options = _set_chrome_options(downloads_path, headless,
                                                 proxy_string, proxy_auth,
                                                 proxy_user, proxy_pass,
                                                 user_agent, disable_csp,
                                                 enable_sync, user_data_dir,
                                                 extension_zip, extension_dir)
            if LOCAL_CHROMEDRIVER and os.path.exists(LOCAL_CHROMEDRIVER):
                make_driver_executable_if_not(LOCAL_CHROMEDRIVER)
                return webdriver.Chrome(executable_path=LOCAL_CHROMEDRIVER,
                                        options=chrome_options)
            else:
                return webdriver.Chrome(options=chrome_options)
        except Exception as e:
            if headless:
                raise Exception(e)
            if LOCAL_CHROMEDRIVER and os.path.exists(LOCAL_CHROMEDRIVER):
                make_driver_executable_if_not(LOCAL_CHROMEDRIVER)
                return webdriver.Chrome(executable_path=LOCAL_CHROMEDRIVER)
            else:
                return webdriver.Chrome()
    else:
        raise Exception("%s is not a valid browser option for this system!" %
                        browser_name)
Beispiel #25
0
 def create_safari(self, desired_capabilities, remote_url):
     if is_truthy(remote_url):
         return self._remote(desired_capabilities, remote_url)
     return webdriver.Safari(**desired_capabilities)
Beispiel #26
0
def browser(name=None, driver_path=None, grid_url=None):
    """
    Run class initialization method, the default is proper
    to drive the Firefox browser. Of course, you can also
    pass parameter for other browser, Chrome browser for the "Chrome",
    the Internet Explorer browser for "internet explorer" or "ie".
    :param name: Browser name
    :param driver_path: Browser driver path
    :param grid_url: Either a string representing URL of the remote server or a custom
             remote_connection.RemoteConnection object.
    :return:
    """
    if name is None:
        name = "chrome"

    if name == "firefox" or name == "ff":
        if driver_path is not None:
            return webdriver.Firefox(executable_path=driver_path)
        if grid_url is not None:
            webdriver.Remote(
                command_executor=grid_url,
                desired_capabilities=DesiredCapabilities.FIREFOX.copy())
        return webdriver.Firefox()
    elif name == "chrome":
        if driver_path is not None:
            return webdriver.Chrome(executable_path=driver_path)
        if grid_url is not None:
            webdriver.Remote(
                command_executor=grid_url,
                desired_capabilities=DesiredCapabilities.CHROME.copy())
        return webdriver.Chrome()
    elif name == "internet explorer" or name == "ie":
        return webdriver.Ie()
    elif name == "opera":
        return webdriver.Opera()
    elif name == "chrome_headless":
        chrome_options = CH_Options()
        chrome_options.add_argument('--headless')
        if driver_path is not None:
            return webdriver.Chrome(chrome_options=chrome_options,
                                    executable_path=driver_path)
        return webdriver.Chrome(chrome_options=chrome_options)
    elif name == "firefox_headless":
        firefox_options = FF_Options()
        firefox_options.headless = True
        if driver_path is not None:
            return webdriver.Firefox(firefox_options=firefox_options,
                                     executable_path=driver_path)
        return webdriver.Firefox(firefox_options=firefox_options)
    elif name == 'edge':
        return webdriver.Edge()
    elif name == 'safari':
        return webdriver.Safari()
    elif name in PHONE_LIST:
        options = CH_Options()
        options.add_experimental_option("mobileEmulation",
                                        {"deviceName": name})
        driver = webdriver.Chrome(chrome_options=options,
                                  executable_path=driver_path)
        driver.set_window_size(width=480, height=900)
        return driver
    elif name in PAD_LIST:
        options = CH_Options()
        options.add_experimental_option("mobileEmulation",
                                        {"deviceName": name})
        driver = webdriver.Chrome(chrome_options=options,
                                  executable_path=driver_path)
        driver.set_window_size(width=1100, height=900)
        return driver
    else:
        raise NameError(
            "Not found '{}' browser, See the help doc: https://github.com/SeldomQA/seldom/blob/master/docs/driver.md'."
            .format(name))
Beispiel #27
0
from selenium import webdriver
import time
import re
import os
import traceback
import csv
import json
import random
import urllib
import time
from googleapiclient.discovery import build
import tkinter as Tk
my_api_key = ""  #Enter Your Google API Key
my_cse_id = ""  #Enter Your Google Custom Search Engine ID

browser = webdriver.Safari()
browser.implicitly_wait(10)


def google_search(search_term, api_key, cse_id, **kwargs):
    service = build("customsearch", "v1", developerKey=api_key)
    print(search_term)
    res = service.cse().list(q=search_term, cx=cse_id, **kwargs).execute()
    results = []
    try:
        for item in res['items']:
            if ("linkedin.com" in item['link']
                    and "linkedin.com/jobs" not in item['link']
                    and "linkedin.com/userp" not in item['link']
                    and "linkedin.com/title" not in item['link']):
                results.append(item['link'])
Beispiel #28
0
 def setUpClass(self):
     self.wd = webdriver.Safari()
Beispiel #29
0
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException

driver = webdriver.Safari()


# returns a mapping of problem tags to the number of times(frequency) it appears in a problem for a given rating
def collect(rating_num):
    # dictionary
    freq = {}

    # base url
    driver.get("https://codeforces.com/problemset?tags=" + str(rating_num) +
               "-&order=BY_RATING_ASC")
    last = 1
    # determine the page number for last page
    for page_num in driver.find_element_by_class_name(
            "pagination").find_elements_by_class_name("page-index"):
        last = max(last, int(page_num.get_attribute("pageindex")))

    # loads pages until it reaches the last page that contains the problems with the given rating number
    for page_num in range(1, last + 1):
        url = "https://codeforces.com/problemset/page/" + str(
            page_num) + "?tags=" + str(rating_num) + "-&order=BY_RATING_ASC"
        driver.get(url)
        # print("navigating to page: " + url)

        # table contains html table
        table = driver.find_element_by_class_name("problems")

        # extract fields from each row and column
Beispiel #30
0
def safari_browser():
    browser = webdriver.Safari()
    return browser