0

I'm trying to automate the filling of an online form, but the input fields seem to be generated at each update having a different ID which doesn't allow the filling as the IDs are always changing.

Is there any solution? suggestions?

Code1 - In this case I can through the 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 In this case it works once but if you refresh the ID it changes and then it doesn't work <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>

...after refresh

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

Astos
  • 1
  • 3
  • Is the website public? If the table always has a fixed number of `td` then you can target table then the td by nth-children? – Raymond Wu Aug 05 '21 at 13:42
  • Ya, I remembered that, but Link can change lines. It's not the ideal solution but it works. In IE it did like this. ... `Dim HTMLDoc As MSHTML.HTMLDocument` `Dim HTMLInput As MSHTML.IHTMLElement, HTMLInput2 As MSHTML.IHTMLElement, HTMLInput3 As MSHTML.IHTMLElement` `Set HTMLInput = HTMLDoc.getElementById("gridview-1048-body")` `Set HTMLInput2 = HTMLInput.getElementsByTagName("tr")(6)` `Set HTMLInput3 = HTMLInput.getElementsByTagName("td")(2)` `HTMLInput3.click` how do I do on Selenium? – Astos Aug 05 '21 at 14:32
  • I don't use Selenium but a quick google have plenty of answers - [Example](https://stackoverflow.com/questions/33977978/selenium-vba-get-element-by-class-name). Check the object browser? @Asantos – Raymond Wu Aug 05 '21 at 14:34

1 Answers1

0

See if this xpath works assuming there is one td with class name "unselectable"

gc.FindElementByXPath("//td[contains(@class,'x-unselectable') and contains(@id,'ext-gen')]")
itronic1990
  • 1,231
  • 2
  • 4
  • 18