Question

I have come across a situation underlying page HTML does not contain the value contained in a readonly textbox. In the browser the textbox was shown to contain the text 'A504Y'.

I was using Webdriver to find the text associated with the textbox. Naturally my first approach was to read the text associated with the textbox using the .text method :

string text = Web.Browser.FindElement(By.Id(ProductVariantCodeId)).Text;

However, this did not work, the text string was returned with a null value.

Inspecting the element (using Chrome) showed the element to be defined by the following code :

<input id="ProductVariantCode" type="text" data-bind="value: ProductVariantCode, attr: {placeholder: ProductVariantCodePlaceHolder}, inputValidation: { }" disabled="disabled" class="disabled" placeholder="Auto Generated" >

Note that the text ‘A504Y’ does not appear in the code, which would explain why Webdriver cannot see it. However my colleague suggested the following Webdriver code to find the value :

string text = Web.Browser.FindElement(By.Id(ProductVariantCodeId)).GetAttribute("value");

This worked.

I am not sure why the ‘A504Y’ text is not present in the HTML which was shown upon inspection. If anyone can explain this please could this be explained.Thanks.

Was it helpful?

Solution

The .Text property refers to the innerText of the html element. The GetAttribute("value") got the text actually contained in the text box. "Value" defined what to access for the GetAttribute method.

I am guessing you are using C#? The api docs might be worth a look for future reference.

http://selenium.googlecode.com/git/docs/api/dotnet/index.html

OTHER TIPS

Get element first and then try-

String s = element.getattribute ("placeholder");

& you will get that value in string. Looks like 'A504Y' is auto generated placeholder in text field

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top