[英]Xpath for checkbox element by locating it's following label element by value
[英]Locating label element using class
我試圖找到標簽元素並用一些值填充它,但我無法獲取它。 我正在使用Java
, testNG
和Selenium
編寫以下代碼。
我使用的代碼如下
driver.findElement(By.className("ng-pristine ng-empty ng-invalid ng-invalid-required ng-valid-maxlength ng-touched")).sendKeys("12345");
要么
driver.findElement(By.className("item-input-wrapper scan-input-label")).sendKeys("12345");
這是我檢查元素時收到的元素的詳細信息。
實際上,硒不支持使用具有復合類名的 By.className()
來定位元素。 您應該嘗試使用By.cssSelector()
來定位<input>
元素,如下所示:-
driver.findElement(By.cssSelector("input[placeholder = 'Scan Container Label']")).sendKeys("12345");
或更具體:
driver.findElement(By.cssSelector("input[placeholder = 'Scan Container Label'][ng-model *= 'ctrl.currentValue']")).sendKeys("12345");
編輯 :-如果要使用其類名查找<label>
元素,請嘗試如下操作:-
driver.findElement(By.cssSelector("label.item-input-wrapper.scan-input-label"));
或者您也可以使用By.className()
與任何人一起找到它,如果單個類名稱為:-
driver.findElement(By.className("item-input-wrapper"));
硒實際上不支持使用By.className()來定位元素。您可以嘗試使用類名css = tagname.classname的css語法
即
driver.findElement(By.cssSelector(input.item-input-wrapper)).sendKeys("12345");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.