我必须更新其元素ID和名称随产品而变化的产品数量。 例如,产品1 ID =" quantity_11046" 产品2 ID =" quantity_15678"
我正在使用css:
WebElement Qty=driver.findElement(By.cssSelector("div:contains(“quantity_1”)");
和
WebElement Qty=driver.findElement(By.cssSelector(""input[id$='quantity_1']");
但是错误无法找到该元素。
<div>
<input type="number" maxlength="3" onkeypress="return isNumeric(event)" oninput="maxLengthCheck(this)" min="1" max="999" ng-model="qty" ng-blur="blurred()" ng-change="changed()" ng-disabled="disabled" ng-readonly="readonly" class="ng-pristine ng-untouched ng-valid ng-valid-min ng-valid-max ng-valid-maxlength" name="quantity_11046" id="quantity_11046">
</div>
答案 0 :(得分:1)
WebElement Qty=driver.findElement(By.cssSelector("input[id^='quantity_']"));
工作谢谢