當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。