0

I'm trying to get values of input element which generated with ko.toJS using Selenium in Firefox:

<input autocomplete="on" class="form-control input-block-level " data-bind="value: $data.Reciever().LastName , disable: !$root.Actions.AllowChange()" data-code-in="false" data-fildid="945" data-param-getall="False" data-povalue="true" id="Reciever_LastName" name="Reciever.LastName" type="text" value="" disabled="" required="">...

JS code looks like this:

$(function () {
            window.DocMVVM = new UMT_Payout_MoneyMVVM(ko.toJS(
{"Sender":{"LastName":"ABC","FirstName":"BCA","Patronymic":"DEF"},
"Reciever":{"LastName":"GHI","FirstName":"IHG","Patronymic":"JKL"},...

I tried by CssSelector

driver.FindElement(By.CssSelector("input.form-control.input-block-level[id='Reciever_LastName']")).GetAttribute("value")

but the result is NULL.

Is anybody had such kind of task and how could I get values of inputs? Thanks.

burnsi
  • 6,194
  • 13
  • 17
  • 27

1 Answers1

0

To retrieve the value attribute from the <input> element you have to induce WebDriverWait for the ElementIsVisible() and you can use either of the following Locator Strategies:

  • CssSelector:

    Console.WriteLine(new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("input.form-control.input-block-level#Reciever_LastName[name='Reciever.LastName']"))).GetAttribute("value"));
    
  • XPath:

    Console.WriteLine(new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//input[@class='form-control input-block-level ' and @id='Reciever_LastName'][@name='Reciever.LastName']"))).GetAttribute("value"));
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352