Need help to fill number into Chrome input box with Selenium

前端 未结 2 1227
终归单人心
终归单人心 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条回答
  • 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
    0 讨论(0)
  • 2020-12-22 08:02

    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")
    
    0 讨论(0)
提交回复
热议问题