首页 文章

Selenium VBA选择选项输入元素

提问于
浏览
2

我正在使用Excel VBA,Selenium和Chrome .

Threse是一个下拉框框,我正在尝试选择一个选项 . Html代码是:

<div class="x-form-field-wrap x-form-field-trigger-wrap x-abs-layout-item x-trigger-wrap-focus" id="ext-gen437" style="width: 100px; left: 330px; top: 70px;">

<input maxlength="1" spellcheck="false" id="ext-comp-1233" name="CITTADINANZA"        class="x-form-text x-form-field x-field-uppercase x-trigger-noedit x-form-focus" readonly="" style="width: 75px;" />

<img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" alt="" class="x-form-trigger x-form-arrow-trigger" id="ext-gen438" />

</div>

显示的文本选项是“Si”和“No”,但在Html代码中没有选项,索引,值...(它只是一个输入元素; img元素是您必须单击下拉列表的箭头)

我尝试使用以下方法填充输入元素:

driver.FindElementByCss("#ext-comp-1233").AsSelect.SelectByIndex
driver.FindElementByCss("#ext-comp-1233").AsSelect.SelectByValue
driver.FindElementByCss("#ext-comp-1233").AsSelect.SelectByText
driver.FindElementByCss("#ext-comp-1233").Sendkeys

但我收到错误:“意外的TagName错误 . 预期=选择Got =输入”

...而Sendkeys不起作用 .

你有什么主意吗?

谢谢 :)

2 回答

  • 0

    试试这个:

    driver.findelementbyxpath("xpath of element").asselect.selectbytext("option text")

  • 1

    解决方案是单击下拉图像,当显示动态创建的div时,单击这些div .

相关问题