📜  Selenium Firefox 配置文件设置首选项 - 任何代码示例

📅  最后修改于: 2022-03-11 14:57:52.392000             🧑  作者: Mango

代码示例1
import requests
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile

# Input capabilities
desired_cap = {
 'browserName': 'firefox',
 'browserVersion': 'latest',
 'os': 'windows',
 'build': 'Python Sample Build',
 'name': 'firefox profile'
}
options = Options()
fp = webdriver.FirefoxProfile()
fp.set_preference('plugin.state.flash', 0)  # Disabling flash using Firefox profile
fp.set_preference('intl.accept_language', 'fr')  # Setting locale language to accept French
# You can make any number of settings using Firefox Profile
fp.update_preferences()
options.profile = fp
driver = webdriver.Remote(
    command_executor='https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub',
    desired_capabilities=desired_cap,
    options=options
    )
# Your test code goes here