Nick Kahn
Nick Kahn

Reputation: 20078

Extracting text from the input field - using Webdriver

How would I extract the text from the input filed? I tried using XPath/CSSSelector but I'm getting an empty text and since its a input field.

Here is my html code:

<div>
     <input type="text" style="width:110px;" class="display">
</div>

Result: 1 to 50 of 195 rows

Here is the screen shot of the input field:

enter image description here

Upvotes: 3

Views: 13181

Answers (2)

Nick Kahn
Nick Kahn

Reputation: 20078

I'm using C# so here is the working complete code:

public string TextAttributeValueByCssSelector(By by)
{
   var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(30));
   return wait.Until(drv => drv.FindElement(by)).GetAttribute("value");
}

Upvotes: 1

Ross Patterson
Ross Patterson

Reputation: 9569

You need to get the field's value. For example: element.get_attribute("value")

Upvotes: 16

Related Questions