1

I'm trying to locate the label element and fill it with some value but I'm not able to get it. I'm using Java, testNG and Selenium to write the below code.

The code that I used is below

driver.findElement(By.className("ng-pristine ng-empty ng-invalid ng-invalid-required ng-valid-maxlength ng-touched")).sendKeys("12345");

OR

driver.findElement(By.className("item-input-wrapper scan-input-label")).sendKeys("12345");

This is the details of element that I received when I inspect the element.

enter image description here

Saurabh Gaur
  • 23,507
  • 10
  • 54
  • 73
AAK
  • 19
  • 1

2 Answers2

3

Actually selenium doesn't support to locate an element using By.className() with compound class name. You should try using By.cssSelector() instead to locate <input> element as below :-

driver.findElement(By.cssSelector("input[placeholder = 'Scan Container Label']")).sendKeys("12345");

Or more specific :-

driver.findElement(By.cssSelector("input[placeholder = 'Scan Container Label'][ng-model *= 'ctrl.currentValue']")).sendKeys("12345");

Edited :- If you want to locate <label> element using their class name try as below :-

driver.findElement(By.cssSelector("label.item-input-wrapper.scan-input-label"));

Or you can locate it also using By.className() with anyone if the single class name as :-

driver.findElement(By.className("item-input-wrapper"));
Saurabh Gaur
  • 23,507
  • 10
  • 54
  • 73
1

Actually selenium doesn't support to locate an element using By.className() You can try syntax of css with classname, css=tagname.classname

i.e.

driver.findElement(By.cssSelector(input.item-input-wrapper)).sendKeys("12345");