I have below two input fields and I have to find there location I can't use class selector cause iI have to identify element based on formcontrolname
and ng-invalid class
<div>
<input _ngcontent-thn-c28="" formcontrolname="nic_no" igxinput="" type="text" placeholder="00000-0000000-0" class="ng-untouched ng-pristine ng-invalid igx-input-group__input">
</div>
<div>
<input _ngcontent-thn-c28="" formcontrolname="username" igxinput="" type="text" placeholder="UserName" class="ng-untouched ng-pristine ng-invalid igx-input-group__input">
</div>
Therefore I'm using xpath. Below is what I did:
driver.findElement(By.xpath("//div/input[(@formcontrolname='nic_no') and (@class='ng-invalid')]");
driver.findElement(By.xpath("//div/input[(@formcontrolname='nic_no') and (@class='ng-invalid')]");
But I'm getting error apparently I have to write all classes name inside @class
, like this:
driver.findElement(By.xpath("//div/input[(@formcontrolname='nic_no') and (@class='ng-untouched ng-pristine ng-invalid igx-input-group__input')]");
If I do like above then I won't get error but I need to use only one class name, cause there are changes more classes may include and reduce from this list of classes.