Python selenium.webdriver.Safari() Examples

The following are 11 code examples of selenium.webdriver.Safari(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module selenium.webdriver , or try the search function .
Example #1
Source File: webpages.py    From eavatar-me with Apache License 2.0 6 votes vote down vote up
def browser(request):
    browser_type = os.environ.get('AVA_TEST_BROWSER', 'Firefox')

    if browser_type == 'PhantomJS':
        b = webdriver.PhantomJS()
    if browser_type == 'Chrome':
        b = webdriver.Chrome()
    elif browser_type == 'Opera':
        b = webdriver.Opera()
    elif browser_type == 'IE':
        b = webdriver.Ie()
    elif browser_type == 'Safari':
        b = webdriver.Safari()
    elif browser_type == 'Remote':
        b = webdriver.Remote()
    else:
        b = webdriver.Firefox()

    b.implicitly_wait(5)

    def teardown_browser():
        b.quit()
    request.addfinalizer(teardown_browser)

    return b 
Example #2
Source File: config_driver.py    From toolium with Apache License 2.0 5 votes vote down vote up
def _setup_safari(self, capabilities):
        """Setup Safari webdriver

        :param capabilities: capabilities object
        :returns: a new local Safari driver
        """
        return webdriver.Safari(desired_capabilities=capabilities) 
Example #3
Source File: webdriver.py    From expressvpn_leak_testing with MIT License 5 votes vote down vote up
def driver(self, browser):
        if browser == 'firefox':
            return webdriver.Firefox()
        if browser == 'chrome':
            return webdriver.Chrome()
        if browser == 'safari':
            return webdriver.Safari()
        if browser == 'opera':
            return webdriver.Opera()
        if browser == 'phantom':
            return webdriver.PhantomJS()
        raise XVEx("{} is not supported on {}".format(browser, self._device.os_name())) 
Example #4
Source File: conftest.py    From marvin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def driver(base_url, osinfo, browserinfo):
    ostype, os_version = osinfo
    browser, browser_version = browserinfo
    buildid = '{0}_{1}_{2}_{3}'.format(ostype.lower().replace(' ', '_'),
                                       os_version.lower().replace(' ', '_'), browser, browser_version)
    # skip some combinations
    if os_version == 'Sierra' and browser == 'safari' and browser_version == '9.1':
        pytest.skip('cannot have Sierra running safari 9.1')
    elif os_version == 'El Capitan' and browser == 'safari' and browser_version == '10':
        pytest.skip('cannot have El Capitan running safari 10')

    # set driver
    if browserstack:
        username = os.environ.get('BROWSERSTACK_USER', None)
        access = os.environ.get('BROWSERSTACK_ACCESS_KEY', None)
        desired_cap = {'os': ostype, 'os_version': os_version, 'browser': browser, 'build': buildid,
                       'browser_version': browser_version, 'project': 'marvin', 'resolution': '1920x1080'}
        desired_cap['browserstack.local'] = True
        desired_cap['browserstack.debug'] = True
        desired_cap['browserstack.localIdentifier'] = os.environ['BROWSERSTACK_LOCAL_IDENTIFIER']
        driver = webdriver.Remote(
            command_executor='http://{0}:{1}@hub.browserstack.com:80/wd/hub'.format(username, access),
            desired_capabilities=desired_cap)
    else:
        if browser == 'chrome':
            driver = webdriver.Chrome()
        elif browser == 'firefox':
            driver = webdriver.Firefox()
        elif browser == 'safari':
            driver = webdriver.Safari()

    driver.get(base_url)
    yield driver
    # teardown
    driver.quit() 
Example #5
Source File: Safari.py    From jarvis with MIT License 5 votes vote down vote up
def get_driver(self):
        driver = webdriver.Safari()
        cmd = """ osascript -e 'tell application "System Events" to keystroke "h" using {command down}' """
        os.system(cmd)
        return driver 
Example #6
Source File: selenium_test_case.py    From iguana with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
def setUpClass(cls):
        super(SeleniumTestCase, cls).setUpClass()

        # load the webdriver setting as late as possible
        # this is needed when no web driver is specified and no functional tests should be run
        from common.settings.webdriver import WEBDRIVER

        if WEBDRIVER == "firefox":
            firefox_opt = None
            if settings.FUNCTESTS_HEADLESS_TESTING:
                firefox_opt = webdriver.FirefoxOptions()
                firefox_opt.headless = True
            cls.selenium = webdriver.Firefox(firefox_options=firefox_opt)
        elif WEBDRIVER == "chrome":
            chrome_opt = None
            if settings.FUNCTESTS_HEADLESS_TESTING:
                chrome_opt = webdriver.ChromeOptions()
                chrome_opt.headless = True
            cls.selenium = webdriver.Chrome(options=chrome_opt)
        elif WEBDRIVER == "safari":
            # headless mode is not possible right now in Safari
            # see https://github.com/SeleniumHQ/selenium/issues/5985
            cls.selenium = webdriver.Safari()
        else:
            raise Exception("Webdriver not configured probably!")
        cls.selenium.implicitly_wait(settings.FUNCTESTS_DEFAULT_WAIT_TIMEOUT) 
Example #7
Source File: xzl.py    From xzl with MIT License 5 votes vote down vote up
def get_subscribes():
    print('开始采集订阅列表\n')
    url = xzl + '/' + 'me/subscribes'
    driver = webdriver.Safari()
    driver.get(xzl)
    cookies = headers.get('Cookie').replace(' ', '').split(';')
    for cookie in cookies:
        cs = cookie.split('=')
        driver.add_cookie({'name': cs[0], 'value': cs[1]})
    driver.get(url)
    print('开始采集订阅目录, 采集完成后自动关闭浏览器\n')
    style = ''
    while not style == 'display: block;':
        print('正在采集。。。\n')
        time.sleep(seconds)
        # 此处模拟浏览器滚动, 以采集更多数据
        js = "window.scrollTo(0, document.documentElement.scrollHeight*2)"
        driver.execute_script(js)
        style = driver.find_element_by_class_name('xzl-topic-list-no-topics').get_attribute('style')
    selector = Selector(text=driver.page_source)
    items = selector.css(u'.streamItem-cardInner').extract()
    print('列表采集完成,共找到%d条数据\n'%len(items))
    for item in items:
        selector = Selector(text=item)
        href = selector.css(u'.zl-title a::attr(href)').extract_first()
        title = selector.css(u'.zl-title a::text').extract_first()
        book = selector.css('.zl-bookContent').extract_first()
        print('开始采集: ' + title + '的目录信息\n')
        if book:
            print('当前内容为小书\n')
            get_xs(href, True)
        else:
            print('当前内容为专栏\n')
            get_zl(href, driver)
        time.sleep(seconds)
    print('所有内容已导出完成,我们应该尊重每一位作者的付出,请不要随意传播下载后的文件\n')


# 采集小书章节目录 
Example #8
Source File: browser.py    From capybara.py with MIT License 5 votes vote down vote up
def get_browser(browser_name, capabilities=None, **options):
    """
    Returns an instance of the given browser with the given capabilities.

    Args:
        browser_name (str): The name of the desired browser.
        capabilities (Dict[str, str | bool], optional): The desired capabilities of the browser.
            Defaults to None.
        options: Arbitrary keyword arguments for the browser-specific subclass of
            :class:`webdriver.Remote`.

    Returns:
        WebDriver: An instance of the desired browser.
    """

    if browser_name == "chrome":
        return webdriver.Chrome(desired_capabilities=capabilities, **options)
    if browser_name == "edge":
        return webdriver.Edge(capabilities=capabilities, **options)
    if browser_name in ["ff", "firefox"]:
        return webdriver.Firefox(capabilities=capabilities, **options)
    if browser_name in ["ie", "internet_explorer"]:
        return webdriver.Ie(capabilities=capabilities, **options)
    if browser_name == "phantomjs":
        return webdriver.PhantomJS(desired_capabilities=capabilities, **options)
    if browser_name == "remote":
        return webdriver.Remote(desired_capabilities=capabilities, **options)
    if browser_name == "safari":
        return webdriver.Safari(desired_capabilities=capabilities, **options)

    raise ValueError("unsupported browser: {}".format(repr(browser_name))) 
Example #9
Source File: DriverFactory.py    From qxf2-page-object-model with MIT License 4 votes vote down vote up
def run_local(self,os_name,os_version,browser,browser_version):
        "Return the local driver"
        local_driver = None
        if browser.lower() == "ff" or browser.lower() == 'firefox':
            local_driver = webdriver.Firefox()
        elif  browser.lower() == "ie":
            local_driver = webdriver.Ie()
        elif browser.lower() == "chrome":
            local_driver = webdriver.Chrome()
        elif browser.lower() == "opera":
            try:
                opera_browser_location = opera_browser_conf.location
                options = webdriver.ChromeOptions()
                options.binary_location = opera_browser_location # path to opera executable
                local_driver = webdriver.Opera(options=options)

            except Exception as e:
                print("\nException when trying to get remote webdriver:%s"%sys.modules[__name__])
                print("Python says:%s"%str(e))
                if  'no Opera binary' in str(e):
                     print("SOLUTION: It looks like you are trying to use Opera Browser. Please update Opera Browser location under conf/opera_browser_conf.\n")
        elif browser.lower() == "safari":
            local_driver = webdriver.Safari()

        return local_driver 
Example #10
Source File: xzl.py    From xzl with MIT License 4 votes vote down vote up
def get_zl(href, driver=None):
    url = xzl + href
    print('开始采集专栏信息,专栏地址为: ' + url + '\n')
    xzl_path = ''
    if not driver:
        driver = webdriver.Safari()
        driver.get(xzl)
        cookies = headers.get('Cookie').replace(' ', '').split(';')
        for cookie in cookies:
            cs = cookie.split('=')
            driver.add_cookie({'name': cs[0], 'value': cs[1]})
    else:
        xzl_path = '小专栏/'
    driver.get(url)
    print('开始采集专栏文章目录\n')
    style = ''
    while not style == 'display: block;':
        print('正在采集。。。\n')
        time.sleep(seconds)
        # 此处模拟浏览器滚动, 以采集更多数据
        js = "window.scrollTo(0, document.documentElement.scrollHeight*2)"
        driver.execute_script(js)
        style = driver.find_element_by_class_name('xzl-topic-list-no-topics').get_attribute('style')
    selector = Selector(text=driver.page_source)
    items = selector.css(u'.topic-body').extract()
    print('采集文章数量: %d篇\n'%len(items))
    zl_title = selector.css(u'.zhuanlan-title ::text').extract_first().replace('\n', '').replace(' ', '')
    print('目录采集完成, 正在采集的专栏为: ' + zl_title + ', 开始为您创建存储路径\n')
    path = os.path.join(os.path.expanduser("~"), 'Desktop') + '/' + xzl_path + zl_title + '/'
    print('文件存储位置: ' + path + '\n')
    if not os.path.exists(path):
        os.makedirs(path)
        print('文件夹创建成功\n')
    print('开始采集文章详情\n')
    for idx, item in enumerate(items):
        selector = Selector(text=item)
        link = selector.css(u'a::attr(href)').extract_first()
        title = selector.css(u'h3::text').extract_first().replace('\n', '').replace(' ', '').replace('/', '-')
        detail_url = xzl+link
        print('开始采集文章: ' + title + ', 文章地址为: ' + detail_url + '\n')
        get_zl_detail(detail_url, path, title)
        # 延迟三秒后采集下一文章
        time.sleep(seconds)
    print('专栏:' + zl_title + '的文章已采集完成' + '\n')
    print('我们应该尊重每一位作者的付出, 请不要随意传播下载后的文件\n')


# 采集专栏详情 
Example #11
Source File: DriverFactory.py    From makemework with MIT License 2 votes vote down vote up
def run_local(self,os_name,os_version,browser,browser_version):
        "Return the local driver"
        local_driver = None
        if browser.lower() == "ff" or browser.lower() == 'firefox':
            local_driver = webdriver.Firefox()    
        elif  browser.lower() == "ie":
            local_driver = webdriver.Ie()
        elif browser.lower() == "chrome":
            local_driver = webdriver.Chrome()
        elif browser.lower() == "opera":
            opera_options = None
            try:
                opera_browser_location = opera_browser_conf.location
                options = webdriver.ChromeOptions()
                options.binary_location = opera_browser_location # path to opera executable
                local_driver = webdriver.Opera(options=options)
                    
            except Exception as e:
                print("\nException when trying to get remote webdriver:%s"%sys.modules[__name__])
                print("Python says:%s"%str(e))
                if  'no Opera binary' in str(e):
                     print("SOLUTION: It looks like you are trying to use Opera Browser. Please update Opera Browser location under conf/opera_browser_conf.\n")
        elif browser.lower() == "safari":
            local_driver = webdriver.Safari()

        return local_driver