首页 > 解决方案 > 如何通过 Selenium VBA 向某些 HTML 元素发送文本?

问题描述

我在通过 VBA 中的 Selenium 引用网站上的搜索框时遇到了麻烦。盒子的HTML代码是:

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

我努力了

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")

但它们似乎都不起作用。任何帮助是极大的赞赏。

标签: excelvbaseleniumxpathcss-selectors

解决方案


要在所需元素中发送字符序列,您可以使用以下任一Locator Strategies

  • 使用FindElementByCss

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

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

参考

您可以在以下位置找到一些相关的讨论:


推荐阅读