SeleniumBasic
SeleniumBasic copied to clipboard
Selenium Basic - Find Element and Extract for Excel
I'm trying to locate an element inside a table to extract it but with selenium I'm not getting it. I do this with VBA using this encoding:
For Each i In IE.Document.body.getElementsByTagName("table") If InStr(i.innertext, "Nome") > 0 Then For Each l In i.getElementsByTagName("tr") If InStr(l.innertext, Orgão) Then Range("C" & lcontador).Value = l.getElementsByTagName("td")(1).innertext End If
I am putting prints of the screens when the element is not available, the message "No registry was found" appears and the example of when it appears with the sequence appears "5600020180015" which is the number that I want to extract. These two information appear in the same table that after much research I found the XPath of it ".//*[@id = 'ListPrograms Query']".
This " 5600020180015 </ a> "is the element that is referenced in this excerpt from the code = Range (" C "& lcount) .Value = l.getElementsByTagName (" td ") (1) .innertext that goes to the worksheet.
Thanks for the help.
Using Google Chrome browser right click on the element, select Inspect. A new window will open with code highlighted for the element, right click on the highlighted code navigate to Copy and select Xpath. Xpath will be copied to your clipboard to the specific element.
I've done this. I used the driver.findelementbyxpath so that when the "5600020180015" element is available it copies to the cell and if it is not and the element found is "Nenhum Registro foi Encontrado" it presses the "Nova Consulta" button to proceed with the script. But the script for when it does not find the first item it stops by not finding and in fact I no longer know if I declared it correctly.