Selenium中的element.sendKeys(密码)方法发送了太多密钥

时间:2017-06-19 20:07:51

标签: java selenium selenium-webdriver

我正在为我公司正在开展的应用程序编写Selenium测试。它是Selenium 3,我使用的是32位Internet Explorer驱动程序(IEDriverServer.exe),因为我使用的是64位版本,但执行任何操作都非常慢。

我尝试填充密码字段(ID ="密码"),并且我使用以下代码行:

driver.findElement(By.id("password")).sendKeys("welcome123");

其中driverInternetExplorerDriver。发生了什么而不是输入10个字符" welcome123",是这样的:

The image of the populated password field

请让我知道如何阻止这种情况发生。我不知道发送了哪些密钥,但我确信在我的代码中它只是说#34; welcome123"而不是像#34; welcome123 _________"。

谢谢!

1 个答案:

答案 0 :(得分:0)

使用线

driver.findElement(By.id("password")).click();

driver.findElement(By.id("password")).click();然后用

跟进

sendKeys("welcome123");

方法调用,正确填充该字段。问题是因为IE是基于密码保存设置自动填充密码字段,它只是在最后添加“welcome123”。