问题描述
这项工作适用于一家目前使用 selenium 3 驱动程序来处理 chrome、ff、edge 等的大公司。我们刚刚增加了 edge selenium 测试的覆盖范围,在这样做的同时,我注意到一些额外的参数可以被添加到chrome不能被这个版本的edge驱动。我对硒方面还很陌生,所以如果这些问题中的任何一个不清楚,我深表歉意。
我的问题与此问题中提供的解决方案有关:How to remove the infobar "Microsoft Edge is being controlled by automated test software" in selenium test
在顶部回复的底部,他们最终获得了 selenium-edge-driver 的 4.0.0-alpha-4 版本。我假设前缀是 Selenium 4 而不是我们目前使用的?将版本 4 用于 Edge 而保留其他版本的旧版本可能行不通。
如果是这种情况,而不是彻底检查所有内容,Selenium 3 上是否有任何选项可以为 Chrome 等 Edge 浏览器添加标志(即“--use-file-for-fake-audio-capture=")或Selenium 4 是唯一的选择吗?这将适用于 Edge 发布版本 80(当前版本为 87)。
解决方法
您必须使用 https://mvnrepository.com/artifact/com.microsoft.edge/msedge-selenium-tools-java 中的边缘选项,而不是普通边缘选项
对于java,使用以下代码:
import org.openqa.selenium.chrome.ChromeOptions;
import com.microsoft.edge.seleniumtools.EdgeOptions;
private static void setEdgeCapabilities(@NonNull final String browser,@NonNull final DesiredCapabilities capabilities) {
ChromeOptions options=new ChromeOptions();
EdgeOptions option=new EdgeOptions().merge(options);
option.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.ACCEPT);
option.setAcceptInsecureCerts(true);
option.addArguments("--no-sandbox");
option.addArguments("--disable-dev-shm-usage");
option.addArguments(Arrays.asList("--start-maximized","--use-fake-ui-for-media-stream","--use-fake-device-for-media-stream","--auto-select-desktop-capture-source=Entire screen","--ignore-certificate-errors"));
option.merge(capabilities);
capabilities.setCapability(ChromeOptions.CAPABILITY,option);