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.