在运行时更改浏览器首选项? [英] Change browser preferences in runtime?

查看:191
本文介绍了在运行时更改浏览器首选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以在运行时更改浏览器首选项吗?

Can we change browser preferences in runtime?

是否有可能在以编程方式执行过程中启动浏览器之前更改浏览器的偏好设置?

Is there any possibility to changes the browser preferences set before launching the browser during execution programmatically?

示例:

在启动驱动程序之前,我已经设置了以下首选项

I have set the following preferences before launching the driver

firefoxProfile.setPreference("pdfjs.disabled", true);
firefoxProfile.setPreference("plugin.scan.plid.all", false);
firefoxProfile.setPreference("plugin.scan.Acrobat", "99.0");

我想将首选项更改为:

firefoxProfile.setPreference("pdfjs.disabled", **false**);
firefoxProfile.setPreference("plugin.scan.plid.all", **true**);
firefoxProfile.setPreference("plugin.scan.Acrobat", "99.0");

请帮助!

谢谢

推荐答案

可以在运行时使用about:config UI更改设置.下面的代码演示了如何做到这一点

It possible to change the settings at run-time using about:config UI. Below code demonstrates how to do the same

from selenium import webdriver

profile = webdriver.FirefoxProfile()
profile.set_preference("general.warnOnAboutConfig", False)

driver = webdriver.Firefox(firefox_profile=profile)

driver.get("about:config")

def set_bool_preferce(name, value):
    value = 'true' if value else 'false';

    driver.execute_script("""
        document.getElementById("textbox").value = arguments[0];
        FilterPrefs();
        view.selection.currentIndex = 0;

        if (view.rowCount == 1) {
           current_value = view.getCellText(0, {id:"valueCol"});
           if (current_value != arguments[1]) {
               ModifySelected();
           }
        } 
    """, name, value)


def set_string_preferce(name, value):

    modified = driver.execute_script("""
        document.getElementById("textbox").value = arguments[0];
        FilterPrefs();
        view.selection.currentIndex = 0;

        if (view.rowCount == 1) {
           current_value = view.getCellText(0, {id:"valueCol"});
           if (current_value != arguments[1]) {
               ModifySelected();
               return true;
           }
        } 

        return false;
    """, name, value)

    if modified is None or modified is True:
        alert = driver.switch_to.alert
        alert.send_keys(value)
        alert.accept()


set_bool_preferce("pdfjs.disabled", True)
set_string_preferce("plugin.disable_full_page_plugin_for_types", "application/pdf,application/pdf2")

driver.quit()

这篇关于在运行时更改浏览器首选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆