当前位置: 首页>>代码示例>>Python>>正文


Python webdriver.Safari方法代码示例

本文整理汇总了Python中selenium.webdriver.Safari方法的典型用法代码示例。如果您正苦于以下问题:Python webdriver.Safari方法的具体用法?Python webdriver.Safari怎么用?Python webdriver.Safari使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在selenium.webdriver的用法示例。


在下文中一共展示了webdriver.Safari方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: browser

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Safari [as 别名]
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 
开发者ID:eavatar,项目名称:eavatar-me,代码行数:27,代码来源:webpages.py

示例2: _setup_safari

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Safari [as 别名]
def _setup_safari(self, capabilities):
        """Setup Safari webdriver

        :param capabilities: capabilities object
        :returns: a new local Safari driver
        """
        return webdriver.Safari(desired_capabilities=capabilities) 
开发者ID:Telefonica,项目名称:toolium,代码行数:9,代码来源:config_driver.py

示例3: run_local

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Safari [as 别名]
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 
开发者ID:qxf2,项目名称:makemework,代码行数:28,代码来源:DriverFactory.py

示例4: run_local

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Safari [as 别名]
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 
开发者ID:qxf2,项目名称:qxf2-page-object-model,代码行数:27,代码来源:DriverFactory.py

示例5: driver

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Safari [as 别名]
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())) 
开发者ID:expressvpn,项目名称:expressvpn_leak_testing,代码行数:14,代码来源:webdriver.py

示例6: driver

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Safari [as 别名]
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() 
开发者ID:sdss,项目名称:marvin,代码行数:37,代码来源:conftest.py

示例7: get_driver

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Safari [as 别名]
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 
开发者ID:edisonwong520,项目名称:jarvis,代码行数:7,代码来源:Safari.py

示例8: setUpClass

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Safari [as 别名]
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) 
开发者ID:iguana-project,项目名称:iguana,代码行数:28,代码来源:selenium_test_case.py

示例9: get_subscribes

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Safari [as 别名]
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')


# 采集小书章节目录 
开发者ID:iizvv,项目名称:xzl,代码行数:41,代码来源:xzl.py

示例10: get_browser

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Safari [as 别名]
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))) 
开发者ID:elliterate,项目名称:capybara.py,代码行数:33,代码来源:browser.py

示例11: get_zl

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Safari [as 别名]
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')


# 采集专栏详情 
开发者ID:iizvv,项目名称:xzl,代码行数:50,代码来源:xzl.py


注:本文中的selenium.webdriver.Safari方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。