动态元素的css选择器 [英] css selector for the dynamic element

查看:169
本文介绍了动态元素的css选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须更新其元素ID和名称随产品而变化的产品的数量. 例如产品1 id ="quantity_11046" 产品2 id ="quantity_15678"

I have to update the Quantity of the product whose element id and name changes with product. eg for Product 1 id="quantity_11046" Product 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']");

但是遇到无法找到元素的错误.

But getting error unable to find the element.

<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>

推荐答案

WebElement Qty=driver.findElement(By.cssSelector("input[id^='quantity_']")); 

工作谢谢

这篇关于动态元素的css选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆