我无法使用Selenium命令访问HTML页面上存在的元素。我尝试了一切:找到类,Id和CSS,但没有工作。也许有路径搜索的方法,但不知道,我不能表述它。有人能帮我吗?
这是HTML:
<input type="text" name="search" value="" placeholder="Cerca per prodotto" class="form-control input-lg searchInputHeader">
我希望能够在HTML页面的搜索字段中输入位于Excel工作表上的值,使用.SendKeys
指令。
例如:
.FindElementsByClass("form-control input-lg searchInputHeader").SendKeys Cells(4, VbaPosizione)
但并不'work。
您好像遇到了" Compound class names not allowed "错误。这意味着FindElementsByClass
只接受一个类名。
如果你想使用多个类名来选择一个元素,你可以使用这样的CSS选择器(以点作为前缀,不同的类名之间没有空格):
.FindElementByCss(".form-control.input-lg.searchInputHeader")
另外,调试代码的一个好习惯是将步骤分成多行。例如,你可以分别执行Selection和SendKeys:
Dim MyInput As WebElement
Set MyInput = MyWebDriver.FindElementByCss(".form-control.input-lg.searchInputHeader")
MyInput.SendKeys "Some text"