微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用硒在Edge上接受麦克风和相机权限

如何解决使用硒在Edge上接受麦克风和相机权限

我正在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);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。