3

I want to pull the value of 3745 from the AGX9 Monaural pricing field so I can add it to a DataTable. However input.Text is coming up empty and I don't see that actual value of 3745 in the HTML for this page.

enter image description here

Here is the HTML for this input element:

<td class="monaural" ng-class="{'has-error' : vm.pricingForm[i].$invalid && vm.pricingForm[i].$dirty}" ng-init="i = ha + 'Monaural'">
    <span class="caption caption-currency">$</span>
    <input class="form-control price-control ng-pristine ng-valid ng-valid-required ng-valid-pattern ng-touched" type="text" required="" ng-pattern="/^[0-9]{3,5}(\.[0-9]{2})?$/" ng-model="vm.data[2][i].value" name="agx9Monaural">
</td>

Here is the code I am using to attempt to add the label, monaural, and binaural price to a DataTable.

        foreach (IWebElement row in rows)
        {
            var inputFields = row.FindElements(By.TagName("input"));

            //monoaural add to dataTableRow
            dr[1] = inputFields[0].Text;

            //binaural add to dataTableRow
            dr[2] = inputFields[1].Text;

            actualDataTable.Rows.Add(dr);
        }

1 Answer 1

5

You need to get the value attribute

string value = Driver.FindElement(By.Name("agx9Monaural")).GetAttribute("value");

Should do it

In your case it would be

foreach (IWebElement row in rows)
{
    var inputFields = row.FindElements(By.TagName("input"));

    //monoaural add to dataTableRow
    dr[1] = inputFields[0].GetAttribute("value");

    //binaural add to dataTableRow
    dr[2] = inputFields[1].GetAttribute("value");

    actualDataTable.Rows.Add(dr);
}
Sign up to request clarification or add additional context in comments.

2 Comments

Works perfectly, thank you! I made a typo above, the binaural value should be saved into dr[2].
When AngularJS is implemented as part of the application development, then Text property does not work, instead we need to get the attribute value of that control (HTML having attributes with ng-XXXX)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.