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


Python FirefoxProfile.set_preference方法代码示例

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


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

示例1: _create_profile

# 需要导入模块: from selenium.webdriver import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.FirefoxProfile import set_preference [as 别名]
 def _create_profile(self):
     """Create profile object.
     """
     profile = FirefoxProfile()
     for name, value in self.default_profile.items():
         profile.set_preference(name, value)
     return profile
开发者ID:TakesxiSximada,项目名称:pywad,代码行数:9,代码来源:firefox.py

示例2: start

# 需要导入模块: from selenium.webdriver import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.FirefoxProfile import set_preference [as 别名]
    def start(cls, url, driver=""):
        if cls.mode == "FireFox":
            default_profile = {
                'browser.usedOnWindows10': False,
                'browser.usedOnWindows10.introURL': 'https://www.google.com/',
                'startup.homepage_welcome_url.additional': 'about:blank',
                'browser.startup.homepage_override.mstone': 'ignore',
            }
            profile = FirefoxProfile()
            for name, value in default_profile.items():
                profile.set_preference(name, value)
            cls.driver = webdriver.Firefox(profile)

        elif cls.mode == "Chrome":
            try:
                if driver != "":
                    chromedriver = driver
                    L.info(chromedriver)
                    os.environ["webdriver.chrome.driver"] = chromedriver
                    cls.driver = webdriver.Chrome(chromedriver)
                else:
                    cls.driver = webdriver.Chrome()
            except Exception as e:
                L.warning(str(e))
                raise SeleniumError(
                    "Can't find Selenium Driver Mode. %s" % cls.mode)
        else:
            raise SeleniumError(
                "Can't find Selenium Driver Mode. %s" % cls.mode)

        cls.driver.implicitly_wait(DEFAULT_WAIT)
        cls.driver.set_window_size(WINDOW_SIZE_WIDTH, WINDOW_SIZE_HEIGHT)
        cls.driver.get(url)
        time.sleep(5)
开发者ID:TE-ToshiakiTanaka,项目名称:atve,代码行数:36,代码来源:module.py

示例3: SeleniumBaseTest

# 需要导入模块: from selenium.webdriver import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.FirefoxProfile import set_preference [as 别名]
class SeleniumBaseTest(unittest.TestCase):

    def start_test_weblab_deployment(self):
        # Load the configuration of the weblab instance that we have set up for just this test.
        self.global_config = load_dir('test/deployments/webclient_dummy')

        # Start the weblab instance. Because we have activated the dont-start flag it won't actually
        # start listening on the port, but let us use the Flask test methods instead.
        self.handler = self.global_config.load_process('myhost', 'myprocess')

        self.core_server = GLOBAL_REGISTRY['mycore:[email protected]']

    @classmethod
    def setUpClass(self):

        # Starts a test deployment.
        self.start_test_weblab_deployment()

        if os.environ.get("SELENIUM_HEADLESS") and False:
            self.driver = webdriver.PhantomJS()
        else:
            self.profile = FirefoxProfile()
            self.profile.set_preference("intl.accept_languages", "en")
            self.driver = webdriver.Firefox(self.profile)

        self.driver.set_window_size(1400, 1000)

        # self.driver.implicitly_wait(30)

        self.base_url = "http://localhost:5000/"
        self.verificationErrors = []
        self.accept_next_alert = True

    def is_element_present(self, how, what):
        try: self.driver.find_element(by=how, value=what)
        except NoSuchElementException, e: return False
        return True

    def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException, e: return False
        return True

    def close_alert_and_get_its_text(self):
        try:
            alert = self.driver.switch_to_alert()
            alert_text = alert.text
            if self.accept_next_alert:
                alert.accept()
            else:
                alert.dismiss()
            return alert_text
        finally: self.accept_next_alert = True

    @classmethod
    def tearDownClass(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)
开发者ID:JamesHyunKim,项目名称:weblabdeusto,代码行数:60,代码来源:base.py

示例4: __init__

# 需要导入模块: from selenium.webdriver import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.FirefoxProfile import set_preference [as 别名]
 def __init__(self, cer_data, key_data):
   
   self.temp_cer = self.temp_file(cer_data)
   self.temp_key = self.temp_file(key_data)
   profile = FirefoxProfile(settings.PROFILE_PATH)
   
   for preference in settings.PROFILE_PREFERENCES:
     profile.set_preference(*preference)
   
   self._driver = Firefox(firefox_profile = profile)
   self._driver.get(settings.GET_CFDI_URL)
开发者ID:Alkz6,项目名称:web_utilites,代码行数:13,代码来源:utils.py

示例5: __call__

# 需要导入模块: from selenium.webdriver import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.FirefoxProfile import set_preference [as 别名]
 def __call__(self, config, args):
     profile = FirefoxProfile()
     if config.user_agent:
         profile.set_preference("general.useragent.override",
                                config.user_agent)
     if config.ignore_ssl:
         profile.accept_untrusted_certs = True
     args["firefox_profile"] = profile
     args["capabilities"] = args["desired_capabilities"]
     args.pop("desired_capabilities")
     return args
开发者ID:alisaifee,项目名称:holmium.core,代码行数:13,代码来源:config.py

示例6: start_firefox

# 需要导入模块: from selenium.webdriver import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.FirefoxProfile import set_preference [as 别名]
def start_firefox(proxy=None, user_agent=None):
    p = FirefoxProfile("E://profiles")
    p.accept_untrusted_certs = True
    if user_agent:
        p.set_preference("general.useragent.override", user_agent)
    capabilities = DesiredCapabilities().FIREFOX.copy()
    capabilities['acceptInsecureCerts'] = True

    if proxy:
        p.set_proxy(proxy)
    browser = Firefox(firefox_profile=p, capabilities=capabilities)
    return browser
开发者ID:wangwei0807,项目名称:cv_crawler,代码行数:14,代码来源:seleniumLogin.py

示例7: test_that_we_can_accept_a_profile

# 需要导入模块: from selenium.webdriver import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.FirefoxProfile import set_preference [as 别名]
def test_that_we_can_accept_a_profile(capabilities, webserver):
    profile1 = FirefoxProfile()
    profile1.set_preference("browser.startup.homepage_override.mstone", "")
    profile1.set_preference("startup.homepage_welcome_url", webserver.where_is('simpleTest.html'))
    profile1.update_preferences()

    profile2 = FirefoxProfile(profile1.path)
    driver = Firefox(
        capabilities=capabilities,
        firefox_profile=profile2)
    title = driver.title
    driver.quit()
    assert "Hello WebDriver" == title
开发者ID:SeleniumHQ,项目名称:selenium,代码行数:15,代码来源:ff_profile_tests.py

示例8: setUp

# 需要导入模块: from selenium.webdriver import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.FirefoxProfile import set_preference [as 别名]
    def setUp(self):
        if _platform != "darwin":
            self.display = Display(visible=0, size=(1280, 800))
            self.display.start()

        p = FirefoxProfile()
        p.set_preference("webdriver.log.file", "/tmp/firefox_console")

        self.driver = webdriver.Firefox(p)
        self.base_url = os.getenv('SELENIUM_BASE_URL')
        self.verificationErrors = []
        self.accept_next_alert = True
        self.driver.set_window_size(1280, 800)
        self.project_name = "DBaaS"
开发者ID:globocom,项目名称:iaas-usage,代码行数:16,代码来源:base_functional_test.py

示例9: generate_profile

# 需要导入模块: from selenium.webdriver import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.FirefoxProfile import set_preference [as 别名]
def generate_profile(useragent="(default)"):
    profile = FirefoxProfile()
    if useragent.strip().lower()=="(default)":
        status("Using the default useragent")
        return profile
    elif useragent.strip().lower()=="(random)":
        random_useragent = generate_user_agent(os=('mac', 'linux'))
        profile.set_preference("general.useragent.override", random_useragent) # To make our useragent random
        status("Using random useragent "+random_useragent)
        return profile
    else:
        profile.set_preference("general.useragent.override", useragent)
        status("Using useragent "+useragent)
        return profile
开发者ID:OWASP,项目名称:QRLJacking,代码行数:16,代码来源:browser.py

示例10: firefox_profile

# 需要导入模块: from selenium.webdriver import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.FirefoxProfile import set_preference [as 别名]
def firefox_profile(request):
    profile = FirefoxProfile(request.config.getoption('firefox_profile'))
    for preference in request.config.getoption('firefox_preferences'):
        name, value = preference
        if value.isdigit():
            # handle integer preferences
            value = int(value)
        elif value.lower() in ['true', 'false']:
            # handle boolean preferences
            value = value.lower() == 'true'
        profile.set_preference(name, value)
    profile.update_preferences()
    for extension in request.config.getoption('firefox_extensions'):
        profile.add_extension(extension)
    return profile
开发者ID:ClinicalGraphics,项目名称:pytest-selenium,代码行数:17,代码来源:firefox.py

示例11: __init__

# 需要导入模块: from selenium.webdriver import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.FirefoxProfile import set_preference [as 别名]
    def __init__(self, delay=1, browser="firefox"):
        """delay: Number of extra seconds to wait when a page is
           supposedly loaded. Try raising this in case of weird errors.

           browser: `firefox` or `chrome`. The ChromeDriver executable for your
           OS must be inside the bin directory for Chrome to work. Get it from:
           http://chromedriver.storage.googleapis.com/index.html
        """
        self.extra_delay = delay  # extra time to wait after each operation (s)
        self.temp_dir = mkdtemp()

        self.vdisplay = Xvfb()
        self.vdisplay.start()
        if browser == "firefox":
            profile = FirefoxProfile()
            # Open links in same window
            profile.set_preference("browser.link.open_newwindow", 1)
            # Download to temp dir, for files we can't open inline
            profile.set_preference("browser.download.dir", self.temp_dir)
            profile.set_preference("browser.download.folderList", 2)
            profile.set_preference("browser.download.manager.showWhenStarting",
                                   "False")
            profile.set_preference("browser.helperApps.neverAsk.saveToDisk",
                                   "application/msword, application/vnd.ms-word, application/rtf, application/octet-stream")

            # Add extension for overriding Content-Disposition headers, etc
            extensions_dir = os_sep.join(['bin', 'firefox-plugins-enabled'])
            for filename in listdir(extensions_dir):
                fullfilename = os_sep.join([extensions_dir, filename])
                profile.add_extension(extension=fullfilename)

            driver = Firefox(profile)
        elif browser == "chrome":
            # Add extension for overriding Content-Disposition headers
            options = ChromeOptions()
            options.add_extension('bin/undisposition.crx')
            driver = Chrome(executable_path='bin/chromedriver',
                            chrome_options=options)
        else:
            raise Exception("Not a valid browser name")

        self.selenium_driver = EventFiringWebDriver(driver, CustomListener())
        """selenium_driver is a EventFiringWebDriver, so that it can
           trigger javascript event
        """
        self.browser_version = " ".join([
            self.selenium_driver.capabilities['browserName'],
            self.selenium_driver.capabilities['version']])  # 'Firefox 33.0'
开发者ID:rotsee,项目名称:SDRSkrejper,代码行数:50,代码来源:surfer.py

示例12: setup_firefox_profile

# 需要导入模块: from selenium.webdriver import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.FirefoxProfile import set_preference [as 别名]
    def setup_firefox_profile(self):
        """Return a custom firefox profile with given preferences
        and extensions.

        """
        fp = FirefoxProfile()

        if self.extensions:
            # Load extensions.
            for ext in self.extensions:
                fp.add_extension(ext)

        if self.preferences:
            # Load preferences
            for key, value in self.preferences:
                fp.set_preference(key, value)

        return fp
开发者ID:bluesurfer,项目名称:AuthTokens,代码行数:20,代码来源:crawler.py

示例13: test_that_unicode_prefs_are_written_in_the_correct_format

# 需要导入模块: from selenium.webdriver import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.FirefoxProfile import set_preference [as 别名]
def test_that_unicode_prefs_are_written_in_the_correct_format():
    profile = FirefoxProfile()
    profile.set_preference('sample.preference.2', unicode('hi there'))
    profile.update_preferences()

    assert 'hi there' == profile.default_preferences["sample.preference.2"]

    encoded = profile.encoded
    decoded = base64.b64decode(encoded)
    with BytesIO(decoded) as fp:
        zip = zipfile.ZipFile(fp, "r")
        for entry in zip.namelist():
            if entry.endswith('user.js'):
                user_js = zip.read(entry)
                for line in user_js.splitlines():
                    if line.startswith(b'user_pref("sample.preference.2",'):
                        assert line.endswith(b'hi there");')
            # there should be only one user.js
            break
开发者ID:SeleniumHQ,项目名称:selenium,代码行数:21,代码来源:ff_profile_tests.py

示例14: load_cookie

# 需要导入模块: from selenium.webdriver import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.FirefoxProfile import set_preference [as 别名]
 def load_cookie(self, session_id):
     sessions = json.load(open( self.sessions_file ))
     cookie_path = sessions[str(session_id)]["session_path"]
     url = sessions[str(session_id)]["web_url"]
     # Setting useragent to the same one the session saved with
     useragent = sessions[str(session_id)]["useragent"]
     profile = FirefoxProfile()
     profile.set_preference("general.useragent.override", useragent )
     cookies = pickle.load(open(cookie_path, "rb"))
     try:
         browser = Firefox(profile)
     except:
         error("Couldn't open browser to view session!")
         return
     browser.get(url)
     browser.delete_all_cookies()
     browser.execute_script("window.localStorage.clear()") # clear the current localStorage
     for cookie in cookies:
         browser.add_cookie(cookie)
     status(f"Session {session_id} loaded")
     browser.refresh()
     self.browsers.append(browser)
开发者ID:OWASP,项目名称:QRLJacking,代码行数:24,代码来源:browser.py

示例15: firefox_profile

# 需要导入模块: from selenium.webdriver import FirefoxProfile [as 别名]
# 或者: from selenium.webdriver.FirefoxProfile import set_preference [as 别名]
def firefox_profile(pytestconfig):
    profile = None
    if pytestconfig.getoption('firefox_profile'):
        profile = FirefoxProfile(pytestconfig.getoption('firefox_profile'))
        warnings.warn(
            '--firefox-profile has been deprecated and will be removed in '
            'a future release. Please use the firefox_options fixture to '
            'set a profile path or FirefoxProfile object using '
            'firefox_options.profile.', DeprecationWarning)
    if pytestconfig.getoption('firefox_preferences'):
        profile = profile or FirefoxProfile()
        warnings.warn(
            '--firefox-preference has been deprecated and will be removed in '
            'a future release. Please use the firefox_options fixture to set '
            'preferences using firefox_options.set_preference. If you are '
            'using Firefox 47 or earlier then you will need to create a '
            'FirefoxProfile object with preferences and set this using '
            'firefox_options.profile.', DeprecationWarning)
        for preference in pytestconfig.getoption('firefox_preferences'):
            name, value = preference
            if value.isdigit():
                # handle integer preferences
                value = int(value)
            elif value.lower() in ['true', 'false']:
                # handle boolean preferences
                value = value.lower() == 'true'
            profile.set_preference(name, value)
        profile.update_preferences()
    if pytestconfig.getoption('firefox_extensions'):
        profile = profile or FirefoxProfile()
        warnings.warn(
            '--firefox-extensions has been deprecated and will be removed in '
            'a future release. Please use the firefox_options fixture to '
            'create a FirefoxProfile object with extensions and set this '
            'using firefox_options.profile.', DeprecationWarning)
        for extension in pytestconfig.getoption('firefox_extensions'):
            profile.add_extension(extension)
    return profile
开发者ID:davehunt,项目名称:pytest-selenium,代码行数:40,代码来源:firefox.py


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