Selenium WebDriverIE发送单个字符作为Lowecase

问题描述 投票:0回答:1

我最近从Windows 7更改为Windows 10机器,并且在运行以前运行良好的Cucumber单元测试包时,我现在遇到SendKeys的问题-这导致所有测试意外失败。 SendKeys似乎正在将字符串的第一个字符作为ToLower()发送。

示例:

string User = "ANALYSTUSER"

我将密钥发送为:

SendKeys(User) / SendKeys(User.ToUpper())

并且它总是将字段填充为aNALYSTUSER

我已将NuGet程序包/驱动程序版本回滚到最新的10个版本,但问题仍然存在。 (我也尝试过64位驱动程序。)

  1. Selenium.Support
  2. Selenium.WebDriver
  3. Selenium.WebDriver.IEDriver

有人对导致此问题的原因有什么想法,可以在这里尝试什么?

string internet-explorer selenium-webdriver webdriver sendkeys
1个回答
0
投票
也许该问题与您的网站客户端JavaScript有关,它将更改输入的值,我已经使用以下代码创建了一个示例,在我这一方面效果很好。您可以尝试:

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); } }

© www.soinside.com 2019 - 2024. All rights reserved.