Beispiel #1
0
    def get_remote_options(remoteBrowser, remotePlatform, remoteBrowserVersion,
                           remoteCapabilities):
        if remoteBrowser == RemoteBrowserType.IE:
            options = webdriver.InternetExplorerOptions()
        elif remoteBrowser == RemoteBrowserType.FIREFOX:
            options = webdriver.FirefoxOptions()
        elif remoteBrowser == RemoteBrowserType.CHROME:
            options = webdriver.ChromeOptions()
        elif remoteBrowser == RemoteBrowserType.EDGE:
            options = webdriver.EdgeOptions()
        elif remoteBrowser == RemoteBrowserType.SAFARI:
            options = webdriver.SafariOptions()
        else:
            raise Exception(
                StringProcessor.safeFormatter("Remote browser type " +
                                              remoteBrowser +
                                              " is not supported"))

        # Add a platform setting if one was provided
        if (remotePlatform != "" and "platform" not in remoteCapabilities):
            remoteCapabilities.put("platform", remotePlatform)

        # Add a remote browser setting if one was provided
        if (remotePlatform != "" and "platform" not in remoteCapabilities):
            remoteCapabilities.put("version", remoteBrowserVersion)

        # Add additional capabilities to the driver options
        set_driver_options(options, remoteCapabilities)
        return options
Beispiel #2
0
    def setUp(self):
        self.vars = {}

        timeout = 30.0
        options = webdriver.EdgeOptions()
        options.ignore_local_proxy_environment_variables()
        options.add_argument('one')
        options.add_argument('two')
        options.set_capability('browserName', 'MicrosoftEdge')
        self.driver = webdriver.Remote(
            command_executor='http://addr-of-remote-server.com',
            options=options)
        self.driver.implicitly_wait(timeout)
        add_flow_markers()
        apiritif.put_into_thread_store(timeout=timeout,
                                       func_mode=False,
                                       driver=self.driver,
                                       windows={},
                                       scenario_name='remote_sc')
def test_edge_chromium_manager_with_selenium():
    driver_path = EdgeChromiumDriverManager().install()
    options = webdriver.EdgeOptions(is_legacy=False)
    if get_os_type() == "win64" or "win32":
        path = "C:\\Users\\{0}\\AppData\\Local\\Microsoft\\Edge SxS\\Application\\msedge.exe".format(
            os.getlogin())

        if os.path.isfile(path) and path == "msedge.exe":
            options.binary_location = path
    elif (get_os_type() or "mac64") and not os.path.exists('/usr/bin/msedge'):
        path = "/usr/bin/msedge"
    if se.__version__.startswith('4'):
        edge = webdriver.ChromiumEdge(executable_path=driver_path,
                                      options=options,
                                      port=9516)
        edge.get("http://automation-remarks.com")
        edge.quit()
    else:
        assert False
def edge(headless=True, incognito=True, random_useragent=True):
    driver = None
    try:
        edge_options = webdriver.EdgeOptions()
        edge_options.use_chromium = True
        if headless:
            edge_options.add_argument("headless")
        edge_options.add_argument("disable-gpu")
        driver = webdriver.Edge(edgeinstaller, options=edge_options)
    except Exception as e:
        if driver is not None:
            driver.quit()
            driver = None

        sys.stdout.write('\x1b[1K\r')
        sys.stdout.write("failure in edge function")
        sys.stdout.write(str(e))

        sys.stdout.write('\x1b[1K\r')
    return driver
Beispiel #5
0
def CreateWebDriver(browser, user_data_dir, url, fullscreen,
                    extra_browser_args):
    if browser == 'edge' or browser.endswith('msedge.exe'):
        options = webdriver.EdgeOptions()
        # Set use_chromium to true or an error will be triggered that the latest
        # MSEdgeDriver doesn't support an older version (non-chrome based) of
        # MSEdge.
        options.use_chromium = True
        options.binary_location = browser
        for arg in extra_browser_args:
            options.add_argument(arg)
        logging.debug(" ".join(options.arguments))
        driver = webdriver.Edge(options=options)
    else:
        options = webdriver.ChromeOptions()
        options.binary_location = browser
        options.add_argument('--user-data-dir=%s' % user_data_dir)
        options.add_argument('--no-first-run')
        options.add_argument('--no-default-browser-check')
        options.add_argument('--autoplay-policy=no-user-gesture-required')
        options.add_argument('--start-maximized')
        for arg in extra_browser_args:
            options.add_argument(arg)
        logging.debug(" ".join(options.arguments))
        driver = webdriver.Chrome(options=options)
    driver.implicitly_wait(30)
    if url is not None:
        driver.get(url)
    if fullscreen:
        try:
            video_el = driver.find_element_by_tag_name('video')
            actions = webdriver.ActionChains(driver)
            actions.move_to_element(video_el)
            actions.double_click(video_el)
            actions.perform()
        except exceptions.InvalidSelectorException:
            logging.warning(
                'Could not locate video element to make fullscreen')
    return driver
Beispiel #6
0
 def get_default_edge_options():
     edgeOptions = webdriver.EdgeOptions()
     edgeOptions.setPageLoadStrategy(
         webdriver.PageLoadStrategy.NORMAL.toString())
     return edgeOptions
def edge_options(platform_name):
    options = webdriver.EdgeOptions()
    options.set_capability('platformName', platform_name)
    return options
Beispiel #8
0
import re
import time

from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.by import By

# pip install -U requests[security]

options = webdriver.EdgeOptions()
options.headless = True
driver = webdriver.ChromiumEdge(
    "C:\\Users\\ll057\\Desktop\\edgedriver_win64\\msedgedriver.exe",
    options=options)
url = "https://search.cctv.com/search.php?qtext=%E5%8D%A7%E5%BA%95%20%E6%99%AE%E6%B3%95%E6%A0%8F%E7%9B%AE%E5%89%A7&type=video"
resoult = {}
driver.get(url)
html = driver.page_source
soup = BeautifulSoup(html, 'html.parser')
items = soup.find_all(class_='jvedio')
for item in items:
    if '普法栏目剧' in item.a['title']:
        if '卧底' in item.a['title']:
            resoult[item.a["title"]] = re.findall(r"targetpage=(.+?)&point=",
                                                  item.a['href'])
for page in range(1, 4):
    time.sleep(10)
    page = driver.find_element(By.LINK_TEXT, '下一页')
    page.click()
    time.sleep(10)
    html = driver.page_source