问题描述
我正在Edge浏览器上运行Selenium脚本。其中一项功能需要在两个窗口之间发起音频或视频通话。在chrome中,我们可以在chrome选项中使用“ use-fake-ui-for-media-stream”。 Edge有什么类似的东西吗?如果没有,则有一种方法可以在运行时接受这些警报。我已经尝试-
driver.switchTo().alert().accept()
,
但这还是行不通,并引发错误,提示no such alert present
已编辑
我正在使用Edge铬和Java硒,并具有以下代码中的设置属性。脚本运行时仍然会弹出权限
Map<String,Object> prefs = new HashMap<String,Object>();
prefs.put("profile.default_content_settings.popups",0);
prefs.put("download.default_directory",fileDownloadLocation);
EdgeOptions options= new EdgeOptions();
options.setCapability("prefs",prefs);
options.setCapability("allow-file-access-from-files",true);
options.setCapability("use-fake-device-for-media-stream",true);
options.setCapability("use-fake-ui-for-media-stream",true);
DesiredCapabilities capabilities = DesiredCapabilities.edge;
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS,true);
capabilities.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS,true);
System.setProperty("webdriver.edge.driver",getDriverPath("EDGE"));
driver = new EdgeDriver(options);
driver.manage().window().maximize();
解决方法
我建议您使用以下示例代码进行测试。我尝试使用Edge Chromium浏览器进行测试,看起来好像不是在询问权限弹出窗口。
JAVA代码:
public static void main(String[] args)
{
System.setProperty("webdriver.edge.driver","\\msedgedriver.exe");
EdgeOptions op=new EdgeOptions();
op.addArguments("use-fake-device-for-media-stream");
op.addArguments("use-fake-ui-for-media-stream");
WebDriver browser = new EdgeDriver(op);
browser.get("https://your_URL_here...");
}
,
在Selenium 3.141版本中,我们没有addArguments()方法,但在Selenium 4.0.0 alpha版本中,我们有addArguments()方法
EdgeOptions edgeOpts = new EdgeOptions();
edgeOpts.addArguments("allow-file-access-from-files");
edgeOpts.addArguments("use-fake-device-for-media-stream");
edgeOpts.addArguments("use-fake-ui-for-media-stream");
edgeOpts.addArguments("--disable-features=EnableEphemeralFlashPermission");
driver = new EdgeDriver(edgeOpts);