需要帮助使用 Selenium 在 Chrome 输入框中填写数字 [英] Need help to fill number into Chrome input box with Selenium

查看:30
本文介绍了需要帮助使用 Selenium 在 Chrome 输入框中填写数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我一直在尝试在 Excel (2013) VBE 中使用 Selenium Basic ChromeDriver (v 75.0.3770.140) 在 Chrome (v 75.0.3770.142) 的输入框中填写一个数字我尝试了以下但收到错误消息:

Hi I've been trying to fill a number in an input box in Chrome (v 75.0.3770.142) using Selenium Basic ChromeDriver (v 75.0.3770.140) in Excel (2013) VBE I've tried the below but get error message:

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:

(1) HTML before clicking within the input element:

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

(2) HTML after clicking within the input element:

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

(3) HTML after sending some text manually (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>

推荐答案

终于想通了,前面的div类也可以使用:

finally figured out that it works with the div class also in front:

obj.FindElementByXPath("//div[@class='form-group']/input[@class='form-control ng-pristine ng-untouched ng-invalid ng-invalid-required'and @id= 'cartPrdQtyBtn0']").SendKeys ("100000")

这篇关于需要帮助使用 Selenium 在 Chrome 输入框中填写数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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