无法使用Selenium Chrome驱动程序设置提示框值

时间:2016-06-23 10:58:23

标签: c# selenium selenium-chromedriver

我正在使用Selenium Chrome驱动程序在Chrome浏览器中自动化网络应用程序。我收到一个Prompt Box弹出窗口,我无法输入值。 这是代码 -

chromeDriver.SwitchTo().Alert().SendKeys("Some value");

代码成功执行,但在提示框内的文本框中没有设置值。 虽然我能够使用此代码获取提示框的文本值 -

chromeDriver.SwitchTo().Alert().Text;

我的Chrome版本为-46.0.2490.80

知道为什么它不起作用吗?

2 个答案:

答案 0 :(得分:1)

try
   {
      IAlert alert = driver.SwitchTo().Alert();
   if (alert != null)
   {
      alert.SendKeys("Some value");
      alert.Accept();
   }
}
catch (Exception ex) { }

答案 1 :(得分:0)

试试这个

chromeDriver.switchTo().activeElement().sendKeys("Some value");