SeleniumBasic icon indicating copy to clipboard operation
SeleniumBasic copied to clipboard

Selenium Basic - Find Element and Extract for Excel

Open Nill2016 opened this issue 6 years ago • 2 comments

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. siconv1 siconv2 siconv3 siconv4

Nill2016 avatar Jun 01 '18 19:06 Nill2016

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.

moreorover avatar Jun 01 '18 19:06 moreorover

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.

Nill2016 avatar Jun 02 '18 15:06 Nill2016