简体   繁体   English

使用类定位标签元素

[英]Locating label element using class

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. 我正在使用JavatestNGSelenium编写以下代码。

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. 这是我检查元素时收到的元素的详细信息。

在此处输入图片说明

Actually selenium doesn't support to locate an element using By.className() with compound class name . 实际上,硒不支持使用具有复合类名的 By.className()来定位元素。 You should try using By.cssSelector() instead to locate <input> element as below :- 您应该尝试使用By.cssSelector()来定位<input>元素,如下所示:-

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 :- 编辑 :-如果要使用其类名查找<label>元素,请尝试如下操作:-

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 :- 或者您也可以使用By.className()与任何人一起找到它,如果单个类名称为:-

driver.findElement(By.className("item-input-wrapper"));

Actually selenium doesn't support to locate an element using By.className() You can try syntax of css with classname, css=tagname.classname 硒实际上不支持使用By.className()来定位元素。您可以尝试使用类名css = tagname.classname的css语法

ie

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM