gpt4 book ai didi

java - webdriver 使用浏览器版本

转载 作者:行者123 更新时间:2023-12-02 06:13:38 26 4
gpt4 key购买 nike

我正在尝试使用 webdriver 中提供的功能并设置浏览器版本。我的 chrome 版本是 32,但尝试在 chrome 30 中运行我的测试。

System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"/drivers/win/chromedriver.exe");

DesiredCapabilities caps = DesiredCapabilities.chrome();
caps.setCapability("version", "30");
WebDriver wd = new ChromeDriver(caps);
System.out.println(((RemoteWebDriver) wd).getCapabilities().getVersion());

当我打印浏览器版本时,其打印浏览器版本为32,但我在功能中将浏览器版本设置为30。我如何以正确的方式使用此功能。

最佳答案

不,你不能。由于您的测试在装有 Chrome 32 的计算机上运行,​​因此您无法将其设置为 Chrome 30,因为您没有 Chrome 30。

即使驱动程序不支持您请求的功能,也不会引发错误,但不一定会创建具有 DesiredCapability

WebDriver 实例。这就是 Selenium 的设计方式。

有关DesiredCapabilties的更多信息,请参阅this question 。我引用 JimEvans 的回答:

The API specifies that desired capabilities be passed into the constructor. However, it may be the case that a driver does not support a feature requested in the desired capabilities. In that case, no error is thrown by the driver, and this is intentional. A capabilities object is returned by the session which indicates the capabilities that the session actually supports.

That is what's actually happening in this case. The PhantomJS driver doesn't support handling alerts, the returned capabilities object indicates as much. In most language bindings, this returned capabilities object is read-only; in language bindings where the returned object may be read-write, modifying these capabilities has no actual effect on the session. In the pending W3C WebDriver specification, there is a requiredCapabilities setting which would throw an exception if the server cannot provide the capability, but that hasn't been implemented by any driver yet as far as I'm aware.

关于java - webdriver 使用浏览器版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21672998/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com