从文本框webdriver java获取文本值

时间:2018-05-31 13:34:34

标签: java selenium-webdriver

我需要从文本框中获取文本值。我尝试使用gettext()但它给了我空值。请建议如何从文本框中获取电子邮件地址值。 Refer the image for html code

2 个答案:

答案 0 :(得分:0)

当您提出问题时,请始终插入您的尝试。不要插入图像来显示代码(或html)。首选直接插入代码。使用您的共享信息,感兴趣的网络元素的标识为EmailAddress。所以,你可以尝试:

findElement(By.id("EmailAddress")).getText();

答案 1 :(得分:0)

尝试使用getAttributefindElement(By.id("EmailAddress")).getAttribute("value")

基于WebElement getText()个文档:

/**
   * Get the visible (i.e. not hidden by CSS) innerText of this element, including sub-elements,
   * without any leading or trailing whitespace.
   *
   * @return The innerText of this element.
   */
  String getText();

因此,<a name="foo">bar</a> getText()将为您提供"bar"

相关问题