我最近从Windows 7更改为Windows 10机器,并且在运行以前运行良好的Cucumber单元测试包时,我现在遇到SendKeys
的问题-这导致所有测试意外失败。 SendKeys
似乎正在将字符串的第一个字符作为ToLower()
发送。
示例:
string User = "ANALYSTUSER"
我将密钥发送为:
SendKeys(User) / SendKeys(User.ToUpper())
并且它总是将字段填充为aNALYSTUSER
!
我已将NuGet
程序包/驱动程序版本回滚到最新的10个版本,但问题仍然存在。 (我也尝试过64位驱动程序。)
有人对导致此问题的原因有什么想法,可以在这里尝试什么?
private const string URL = @"https://www.bing.com/";
private const string IE_DRIVER_PATH = @"E:\webdriver\IEDriverServer_x64_3.14.0"; // where the Selenium IE webdriver EXE is.
static void Main(string[] args)
{
InternetExplorerOptions opts = new InternetExplorerOptions() { IntroduceInstabilityByIgnoringProtectedModeSettings = true};
using (var driver = new InternetExplorerDriver(IE_DRIVER_PATH, opts))
{
driver.Navigate().GoToUrl("https://www.bing.com/");
var element = driver.FindElementById("sb_form_q");
element.SendKeys("WEBDRIVER");
Console.ReadKey();
}
}
此外,您还可以尝试执行脚本以输入值,如下所示。 private const string URL = @"https://www.bing.com/";
private const string IE_DRIVER_PATH = @"E:\webdriver\IEDriverServer_x64_3.14.0"; // where the Selenium IE webdriver EXE is.
static void Main(string[] args)
{
InternetExplorerOptions opts = new InternetExplorerOptions() { IntroduceInstabilityByIgnoringProtectedModeSettings = true};
using (var driver = new InternetExplorerDriver(IE_DRIVER_PATH, opts))
{
driver.Navigate().GoToUrl("https://www.bing.com/");
var element = driver.FindElementById("sb_form_q");
var script = "document.getElementById('sb_form_q').value = 'webdriver';";
IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
jse.ExecuteScript(script, element);
//element.SendKeys("webdriver");
element.SendKeys(Keys.Enter);
}
}