1

I am having trouble sending value to an element that has a ng-class

I have tried this driver.FindElement(By.Id("limit")).SendKeys("10.00"); but seems to be that element is not recognized. also tried -

driver.FindElement(By.Id("limit_display")).SendKeys("10.00");


<td class="center">
   <amount-input ng-class="{invalid: !addNewCardForm.limit.$valid}"  
            name="limit" amount="newCard.limit" required="" 
            class="ng-isolate-scope">
      <div class="amount-input">
        <div class="currency" ng-class="{degrade: degrade}">$</div>
        <input id="limit_display" name="limit_display" type="text" 
            value="0.00" ng-focus="onFocus()" required="" disable-animate=""> 
        <input id="limit" ng-class="{edit: edit || degrade}" 
            class="entry ng-pristine ng-not-empty ng-valid ng-valid-required ng-touched" 
            name="limit" type="number" ng-model="amount" 
            ng-blur="onBlur()" ng-keydown="onKeyDown($event)" required=""  
            disable-animate="">
      </div>
   </amount-input>
</td>

I expected to send a value

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Budd
  • 59
  • 7

2 Answers2

1

please check if your element is inside frame or not if inside frame then switch to frame then try to operate on element -

you can try following xpath -

driver.FindElement(By.xpath(".//input[@name='limit_display' and @ng-focus='onFocus()']")).SendKeys("10.00");

if still its not working you can try action class -

Actions actions = new Actions(driver);
    actions.moveToElement(element).sendKeys("10.00").build().perform();
Dev
  • 2,739
  • 2
  • 21
  • 34
0

The desired element is an Angular element so you have to induce WebDriverWait for the desired ElementToBeClickable() and you can use either of the following Locator Strategies as solutions:

  • CssSelector:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("input.entry.ng-pristine.ng-not-empty.ng-valid.ng-valid-required.ng-touched[id='limit'][name='limit']"))).SendKeys("10.00");
    
  • XPath:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//input[@class='entry ng-pristine ng-not-empty ng-valid ng-valid-required ng-touched' and @id='limit'][@name='limit']"))).SendKeys("10.00");
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352