【问题标题】:Selenium Webdriver is sending Keys, but no text is displaying in the fieldsSelenium Webdriver 正在发送密钥,但字段中未显示任何文本
【发布时间】:2013-04-24 21:43:25
【问题描述】:

我正在使用 selenium webdriver Chrome。我看到了这么奇怪的东西。我正在测试一个注册帐户。 Webdriver 将进入每个字段,看起来它正在输入文本,但没有显示任何内容。字段中不显示任何文本结果。我做错了什么?

@Test
public void testAlreadyUsedEmailSignUp() throws InterruptedException {
     driver.findElement(By.cssSelector("html body.oneColFixCtrHdr div.container div#header div#innerHeader div#menu ul div.btn-gr")).click();
    Thread.sleep(5000);
    // switch to frames inside the webpage
    driver.switchTo().frame("GB_frame"); // 1st frame
    driver.switchTo().frame(0); // 2nd frame
    driver.findElement(By.id("firstName")).click();
    driver.findElement(By.id("firstName")).sendKeys("Tester");
    driver.findElement(By.id("lastName")).sendKeys("Automater");
    driver.findElement(By.id("email")).sendKeys("test11@gmail.com");
    driver.findElement(By.id("Ppassword")).sendKeys("prd1");
    driver.findElement(By.id("confirmPPassword")).sendKeys("pass7ord1");
    driver.findElement(By.id("State")).sendKeys("I");

    driver.findElement(By.id("myInput")).sendKeys("Mike Ward");

    Thread.sleep(2000);

    driver.findElement(By.name("term")).click();
    driver.findElement(By.id("formAccSubmit")).click();

    assertEquals(driver.findElement(By.id("errorContainer")).getText(),
            "The Email field must contain a valid email address.");

    Thread.sleep(5000);
}

【问题讨论】:

标签: text selenium webdriver field sendkeys


【解决方案1】:

使用下面的代码,你的问题会解决,删除 OR.getProperty 并使用你的属性。

String txtuserzipID = OR.getProperty("txt_UserZip_ID"); 
WebElement txtuserZipInput = driver.findElement(By.id(txtuserzipID));
txtuserZipInput.clear(); 
txtuserZipInput.sendKeys(String.valueOf(79081));
txtuserZipInput = driver.findElement(By.id(txtuserzipID));
new Actions(driver).sendKeys(driver.findElement(By.id(OR.getProperty("txt_UserZip_ID"))), 
"").perform();

希望它能起作用并解决您的问题。 谢谢

【讨论】:

  • 有时 Web 应用程序不会在字段中保存键入的数据。我也面临同样的问题。之后通过使用上面的代码,我已经解决了我的问题..
猜你喜欢
  • 2021-04-21
  • 1970-01-01
  • 1970-01-01
  • 2023-03-07
  • 2012-12-07
  • 1970-01-01
  • 2018-03-27
  • 2013-09-30
  • 1970-01-01
相关资源
最近更新 更多