【问题标题】:Add settings to driver in selenium在 selenium 中为驱动程序添加设置
【发布时间】:2021-07-07 11:17:18
【问题描述】:

您好,我正在尝试在 selenium 中为我的驱动程序添加一些设置,但似乎可以使它们正常工作。

我正在尝试添加

{ 
 "DEVELOPER_MODE":false,
 "AUTOMATION_MODE":true,
 "AUTOMATION_LAUNCH_URL":"{whatever_url_you_want_to_test_with}"
}

到我的驱动文件

     public static WebDriver startDriverTwo() {
        String projectLocation = System.getProperty("user.dir");
        System.setProperty("webdriver.chrome.driver", projectLocation + "/chromedriver.exe");
       

        ChromeOptions opt = new ChromeOptions();
        opt.addArguments("start-maximized");
        opt.addArguments("disable-infobars");
        opt.addArguments("--disable-extensions");
        opt.addArguments("--window-size=1920x1080");
        opt.addArguments("--disable-cache");
        //options.addArguments("--headless");
        opt.addArguments("--disable-application-cache");
        opt.addArguments("--disk-cache-size=0");
        opt.addArguments("--disable-gpu"); // applicable to windows os only
        opt.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
        opt.addArguments("--dns-prefetch-disable");
        opt.addArguments("--disable-notifications");
        opt.addArguments("disable-infobars")

        //Enter the path of your Electron app
        opt.setBinary("pathtoelectronapp.exe");
        driver = new ChromeDriver(opt);
        System.out.println("opening app");
        return driver;


    }

我试过了

setExperimentalOption()
setProperty()

但这些都不起作用?知道我该如何处理这些吗?

【问题讨论】:

    标签: java selenium selenium-webdriver testing selenium-chromedriver


    【解决方案1】:

    DEVELOPER_MODE - 你没看错,是opt.addArguments("--disable-extensions");

    我对这些设置有点困惑,因为:

    AUTOMATION_MODE - 在使用 Selenium 时,这不总是正确的吗?

    AUTOMATION_LAUNCH_URL - 你的意思是driver.get(URL)

    【讨论】:

    • 啊,好吧,我明白了,基本上我是在启动一个电子应用程序而不是 chrome,当我使用 driver.get(URL) 时,我使用“启动”另一个窗口(无法与之交互)的 url,所以我需要它已经“预加载”。在我的本地计算机上,我在 '%APPDATA% 文件中有一个带有这些设置的 json,它运行良好,但是当我从 selenium 启动时,这些设置没有考虑到
    猜你喜欢
    • 2019-09-22
    • 1970-01-01
    • 2020-07-09
    • 2021-05-30
    • 2015-05-23
    • 2015-11-13
    • 2014-09-20
    • 2023-03-21
    • 1970-01-01
    相关资源
    最近更新 更多