【发布时间】:2021-10-10 12:37:28
【问题描述】:
我正在尝试自动填写在线表单,但输入字段似乎在每次更新时生成,具有不同的 ID,由于 ID 总是在变化,因此不允许填写。
有什么解决办法吗?建议?
Code1 - 在这种情况下,我可以通过 name="taxNumber"
<input id="vfenif-1373-inputEl" type="text" size="1" name="taxNumber" class="x-form-field x-form-required-field x-form-text x-form-focus x-field-form-focus x-field-default-form-focus" autocomplete="off" aria-invalid="false" data-errorqtip="" style="width: 100%;">
Private gc As New Selenium.ChromeDriver
...
gc.FindElementByName("taxNumber").SendKeys ("123456789")
...
Code2 在这种情况下它可以工作一次,但如果你刷新 ID,它会发生变化,然后就不能工作了
<td role="gridcell" class="x-grid-cell x-grid-td x-grid-cell-gridcolumn-1047 x-grid-cell-last x-unselectable " id="ext-gen1581"><div unselectable="on" class="x-grid-cell-inner " style="text-align:left;">Submeter Pedido</div></td>
...刷新后
<td role="gridcell" class="x-grid-cell x-grid-td x-grid-cell-gridcolumn-1047 x-grid-cell-last x-unselectable " id="ext-gen1580"><div unselectable="on" class="x-grid-cell-inner " style="text-align:left;">Submeter Pedido</div></td>
【问题讨论】:
-
网站是公开的吗?如果表始终有固定数量的
td,那么您可以将表作为目标,然后是 nth-children 的 td? -
是的,我记得,但是链接可以换行。这不是理想的解决方案,但它有效。在 IE 中它确实是这样的。 ...
Dim HTMLDoc As MSHTML.HTMLDocumentDim HTMLInput As MSHTML.IHTMLElement, HTMLInput2 As MSHTML.IHTMLElement, HTMLInput3 As MSHTML.IHTMLElementSet HTMLInput = HTMLDoc.getElementById("gridview-1048-body")Set HTMLInput2 = HTMLInput.getElementsByTagName("tr")(6)Set HTMLInput3 = HTMLInput.getElementsByTagName("td")(2)HTMLInput3.click在 Selenium 上我该怎么做? -
我不使用 Selenium,但快速谷歌有很多答案 - Example。检查对象浏览器? @阿桑托斯
标签: excel vba selenium screen-scraping