简体   繁体   中英

Getting text value from textbox webdriver java

I need to get the text value from the text box. I tried using gettext() but it gives me empty value. Please suggest how to get the email address value from the text box. Refer the image for html code

When you ask a question insert always your attempts. Don't insert an image to show a code (or html). Prefer insert directly the code. Using your shared infos, the interested web element has as id EmailAddress . So, you could try:

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

Trying using getAttribute : findElement(By.id("EmailAddress")).getAttribute("value")

Based on WebElement getText() docs:

/**
   * 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();

Hence, <a name="foo">bar</a> getText() will give you "bar"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM