How to send text to some HTML elements?

2020-04-20 06:17发布

I have been having trouble on referring to a search box on a website through Selenium in VBA. The HTML code of the box is:

<input type = "search" class ="form-control input-sm"
placeholder aria-controls="result_table"> ==$0

I have tried

bot.findElementByCssSelector(".form-control").SendKeys ("werresf")
bot.findElementByCssSelector(".form-control.input-sm").SendKeys ("werresf")
bot.findElementByCssSelector(".input-sm").SendKeys ("werresf")
bot.findElementByCssSelector(".form-control input-sm").SendKeys ("werresf")
bot.findElementByClassName("form-control input-sm").SendKeys ("werresf")

But none of them seems to work. Any help is greatly appreciated.

1条回答
爷、活的狠高调
2楼-- · 2020-04-20 06:52

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

  • Using FindElementByCss:

    bot.FindElementByCss("input.form-control.input-sm[aria-controls='result_table']").SendKeys ("werresf")
    
  • Using FindElementByXPath:

    bot.FindElementByXPath("//input[@class='form-control input-sm' and @aria-controls='result_table']").SendKeys ("werresf")
    

Reference

You can find a couple of relevant discussions in:

查看更多
登录 后发表回答