如何通过Selenium VBA将文本发送到某些HTML元素? [英] How to send text to some HTML elements through Selenium VBA?
本文介绍了如何通过Selenium VBA将文本发送到某些HTML元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在通过VBA中的Selenium引用网站上的搜索框时遇到了麻烦.该框的HTML代码为:
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
我尝试过
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.
推荐答案
To send a character sequence within the desired element you can use either of the following 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")
您可以在以下位置找到一些相关的讨论:
You can find a couple of relevant discussions in:
- Trying to fill text in input box with dynamic drop down
- Need help to fill number into Chrome input box with Selenium
这篇关于如何通过Selenium VBA将文本发送到某些HTML元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文