嗨,我一直在尝试在Excel(2013)VBE中使用Selenium Basic ChromeDriver(v 75.0.3770.140)在Chrome(v 75.0.3770.142)的输入框中填写一个数字 我尝试了以下操作,但收到错误消息:
obj.FindElementById("cartPrdQtyBtn0").Value = ("100000")
obj.FindElementByCss("input.form-control.ng-pristine.ng-untouched.ng-
invalid.ng-invalid-required#cartPrdQtyBtn0").SendKeys ("10000")
obj.FindElementByXPath("//input[@class='form-control ng-pristine ng-
untouched ng-invalid ng-invalid-required' and
@id='cartPrdQtyBtn0']").SendKeys ("100000")
(1)在输入元素中单击之前的HTML:
<div class="form-group" ng-class="{'has-error':
(entryItem.invalidProductQuantity || entryItem.invalidPallet ||
entryItem.pumpingQtyError || entryItem.lineItemQtyError)}" ng-
hide="entryItem.isPalletEnabled || entryItem.isCancelled"><!-- ngIf: !entryItem.isDecimal --><input id="cartPrdQtyBtn0" type="text"class="form-control ng-pristine ng-untouched ng-invalid ng-invalid-
required"
restrict="number" restrict-max="100000" required="" ng-
model="entryItem.productDisplayQuantity" ng-
readonly="entryItem.isReadOnly"
ng-blur="updateCartProduct(entryItem, $index)" ng-
if="!entryItem.isDecimal">
<!-- end ngIf: !entryItem.isDecimal -->
<!-- ngIf: entryItem.isDecimal -->
</div>
<p ng-bind="entryItem.productDisplayQuantity" ng-show="entryItem.isCancelled" class="ng-hide"></p>
在输入元素中单击后,(2)HTML:
<div class="form-group has-error" ng-class="{'has-error':
(entryItem.invalidProductQuantity || entryItem.invalidPallet ||
entryItem.pumpingQtyError || entryItem.lineItemQtyError)}" ng-
hide="entryItem.isPalletEnabled || entryItem.isCancelled">
<!-- ngIf: !entryItem.isDecimal -->
<input id="cartPrdQtyBtn0" type="text"
class="form-control ng-pristine ng-
invalid ng-invalid-required ng-touched" restrict="number" restrict-
max="100000" required="" ng-model="entryItem.productDisplayQuantity" ng-
readonly="entryItem.isReadOnly" ng-blur="updateCartProduct(entryItem,
$index)" ng-if="!entryItem.isDecimal">
<!-- end ngIf: !entryItem.isDecimal -->
<!-- ngIf: entryItem.isDecimal -->
</div>
<p ng-bind="entryItem.productDisplayQuantity" ng-show="entryItem.isCancelled" class="ng-hide"></p>
(3)手动发送一些文本后的HTML(100000):
<div class="form-group" ng-class="{'has-error':
(entryItem.invalidProductQuantity || entryItem.invalidPallet ||
entryItem.pumpingQtyError || entryItem.lineItemQtyError)}" ng-
hide="entryItem.isPalletEnabled || entryItem.isCancelled">
<input id="cartPrdQtyBtn0" type="text" class="form-control ng-pristine
ng-untouched ng-valid ng-valid-required" restrict="number" restrict-
max="100000" required="" ng-model="entryItem.productDisplayQuantity" ng-
readonly="entryItem.isReadOnly" ng-blur="updateCartProduct(entryItem,
$index)" ng-if="!entryItem.isDecimal">
<p ng-bind="entryItem.productDisplayQuantity" ng-show="entryItem.isCancelled" class="ng-hide">100000</p>
答案 0 :(得分:0)
要在输入字段中发送字符序列,可以使用以下任一Locator Strategies:
startDate
:
cssSelector
obj.FindElementByCss("input.form-control.ng-pristine.ng-untouched.ng-invalid.ng-invalid-required[id^='cartPrdQtyBtn']").Click
obj.FindElementByCss("input.form-control.ng-pristine.ng-invalid.ng-invalid-required.ng-touched[id^='cartPrdQtyBtn']").SendKeys("10000")
:
xpath
注意:由于它是动态元素,因此需要诱使服务生等待元素可点击
答案 1 :(得分:0)
最终发现它也可以与div类一起使用:
obj.FindElementByXPath("//div[@class='form-group']/input[@class='form-control ng-pristine ng-untouched ng-invalid ng-invalid-required'and @id= 'cartPrdQtyBtn0']").SendKeys ("100000")