Il forum si è spostato --> https://forumanicomio.eugy.it
Forum Moved-->

[VB .net / VBA] Get elements DOM XHTML

Rispondi al messaggio


Questa domanda serve a prevenire iscrizioni automatiche.
Emoticon
:rolling: :shock: :chupa: 8-) :oops: :twisted: :roll: ;) :becky: :2frown: :2picche: :acc: :alcesso: :alien: :popcorn: :angel: :angry: :applause: :banana: :berluska: :D :birra: :bleurgh: :boxing: :brindisi: :bugia: :capocc: :china: :clacool: :coffee: :computer: :confused: :contract: :uhm: :upset: :withstup: :yawn: :zitt: :zzz: :lele: :gero: :andy: :urk: :rip: :crazy: :cry: :dottor: :facciada: :fart: :freak: :ghhhhh: :handy: :parsi: :loda: :sisi: :martello: :mucca: :nasega: :pirate: :frank: :abb1: :abb2: XD
Visualizza tutte le emoticon

BBCode attivo
[img] non attivo
[flash] non attivo
[url] attivo
Emoticon attive

Revisione argomento
   

Espandi visuale Revisione argomento: [VB .net / VBA] Get elements DOM XHTML

[VB .net / VBA] Get elements DOM XHTML

da Rombo di Tuono » 02 giu 2017, 15:21


---------------------------------------------------------------------------------------------------------------------------
For my future reference and to help other people banging their head on this... :D

PROBLEM: access an HTML element and change its value with visual basic

TWIST: if the element has an unique value for attribute "name", you may think to access directly that element by its name.

I THINK IT'S IMPOSSIBLE.

GetElementByName doesn't work (or doesn't exist at all) : pay attention to the singular "ElementBy"

GetElementsByName works, BUT IT RETURNS A COLLECTION of objects. pay attention to the plural "ElementsBy"

If you use it this way: obj1=GetElementsByName ("name"), it will end in a obj1 that is a collection, and then it has NOT the "value" property or attribute

So, the correct way to access an element by its unique name is this:

1) Loop For to get all elements by tag name
2) If statement to place an action to a single element

Codice: Seleziona tutto

For Each objLink In IE.Document.GetElementsByTagName("input")
        If objLink.Name = "nGiust0" Then
            objLink.Value = "1"
            Exit For
        End If
Next objLink
"Exit For" is good, because I know that name is unique

If anyone has a better way, please tell me :D

Top