Search code examples
excelvbaselenium-webdriverxpathcss-selectors

How can I input value in TextBox with Selenium VBA


I have this part of HTML:

<input id="naklName" type="text" placeholder="input number document" class="form-control" align="left">

and I can't input value in TextBox with Selenium VBA. May be it works without Selenium.

I tried first XPATH:

bot.FindElementByXpath("//*[@id='naklName']").SendKeys "123"

and other combinations with CLASS, Css, ID. But always NotFoundElement. My VBA code like as:

 Dim bot As New WebDriver   
    bot.Start "chrome", "url"

enter image description here


Solution

  • Given the HTML:

    html

    To send a character sequence within the <input> you can use either of the following locator strategies:

    • Using FindElementByCss:

      bot.FindElementByCss("label[for='naklName']").SendKeys "ENOT"
      
    • Using FindElementByXPath:

      bot.FindElementByXPath("//label[@for='naklName']").SendKeys "ENOT"