0

I want to get value of input tag and compare with sum of 2 numbers. But there is no value tag, or I can not see result number. I tried to get but I got null. The picture and Input tag is like under.

<input _ngcontent-lbg-c92="" matinput="" type="number" class="mat-input-element mat-form-field-autofill-control ng-tns-c35-2 cdk-text-field-autofill-monitored ng-untouched ng-pristine" style="text-align: center;" id="mat-input-2" aria-invalid="false" aria-required="false" disabled="">

Element snapshot:

snapshot

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

0

To print the value i.e. 1626 you can use either of the following locator strategies:

  • Using cssSelector:

    System.out.println(driver.findElement(By.cssSelector("input.mat-input-element[id^='mat-input'][type='number'][matinput]")).getAttribute("value"));
    
  • Using xpath:

    System.out.println(driver.findElement(By.xpath("//input[contains(@class, 'mat-input-element') and starts-with(@id, 'mat-input')][@type='number' and @matinput]")).getAttribute("value"));
    

However, as the element is a dynamic element so to identify the element you need to induce WebDriverWait for the presenceOfElementLocated() and you can use either of the following locator strategies:

  • Using cssSelector:

    System.out.println(new WebDriverWait(driver, 20).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("input[id*='Empty'][value='emptyAssembly']"))).getAttribute("value"));
    
  • Using xpath:

    System.out.println(new WebDriverWait(driver, 20).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[@value='emptyAssembly' and contains(@id, 'Empty')]"))).getAttribute("value"));
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352