-1

I'm trying to find an element but I receive error element not found My code:

    Dim bot As WebDriver
    
    Set bot = New WebDriver
    bot.Start "chrome"
    bot.Get "http://..."
    bot.FindElementByName("userName").SendKeys "text"
    bot.FindElementByName("password").SendKeys "text"
    bot.FindElementByClass("ButtonLast").Click
    
    bot.FindElementByName("searchField").SendKeys "text"
    
    Stop

HTML:

<input
    class="SearchRoundCorner"
    onblur="searchFieldInnerTxt(this);"
    onfocus="searchFieldInnerTxt(this);"
    style="width: 150px; padding-left: 20px; color: rgb(128, 128, 128);"
    type="text"
    name="searchField"
    value="search"
    title=""
    onkeypress="if ((window.event &amp;&amp;  window.event.keyCode == 13)|| event.which==13){ document.ListView.pageNo.value=1;document.ListView.saveSelection.value = 0;submitForm(document.ListView);return false; }"
/>

It works well until I get to that line-bot.FindElementByName("searchField").SendKeys "text"

Error:

Error message:Run-Time Error 7 NoSuchElementError Element not found for name=searchfield

1 Answers1

1

The desired element is a dynamic element, so to send a character sequence to the element you can use either of the following Locator Strategies:

  • Using FindElementByName:

    bot.FindElementByName("searchField").SendKeys "text"
    
  • Using FindElementByCss:

    bot.FindElementByCss("input.SearchRoundCorner[name='searchField'][value='search']").SendKeys "text"
    
  • Using FindElementByXPath:

    bot.FindElementByXPath("//input[@class='SearchRoundCorner' and @name='searchField'][@value='search']").SendKeys "text"
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352