Need help to fill number into Chrome input box with Selenium

前端 未结 2 1275
终归单人心
终归单人心 2020-12-22 07:39

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 bel

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-22 07:50

    To send a character sequence within the input field you can use either of the following Locator Strategies:

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

      obj.FindElementByXPath("//input[@class='form-control ng-pristine ng-untouched ng-invalid ng-invalid-required' and starts-with(@id, 'cartPrdQtyBtn')]").Click
      obj.FindElementByXPath("//input[@class='form-control ng-pristine ng-invalid ng-invalid-required ng-touched' and starts-with(@id, 'cartPrdQtyBtn')]").SendKeys("10000")
      

    Note: As it is a dynamic element you need to induce a waiter for the element to be clickable


    Reference

    You can find a couple of relevant discussions in:

    • How to send text to some HTML elements?
    • Trying to fill text in input box with dynamic drop down

提交回复
热议问题