如何在 Firefox 中使用 Selenium 和 Python 禁用自动完成功能?

如何在 Firefox 中使用 Selenium 和 Python 禁用自动完成功能?

问题描述:

我正在使用 Selenium 构建自动化测试任务.当我将第一个字段放在表单上时,其余部分会根据之前的尝试自动完成.我可以清除字段来处理这个问题,但如果我完全禁用自动完成功能会更容易.
有没有办法在 Python Selenium 中做到这一点?

I am building an automated test task with Selenium. When I put the first field on a form, the rest of it is autocompleted based on previous attempts. I can clear the fields to handle this, but it would be easier if I could disable autocomplete at all.
Is there a way to do this in Python Selenium?

我正在创建一个配置文件:

I am creating a profile with:

profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True
profile.set_preference("security.enable_java", True)
profile.set_preference("plugin.state.java", 2) 
driver = webdriver.Firefox(firefox_profile=profile)

您需要设置browser.formfill.enable Firefox 配置文件首选项 false 要求 Firefox 不记住并自动填充表单输入值:

You need to set browser.formfill.enable firefox profile preference to false to ask Firefox not to remember and autofill form input values:

profile.set_preference("browser.formfill.enable", "false")