Sign in to follow this  
Followers 0
Jfish

Get all HMTL elements with same ID - not in table

5 posts in this topic

I apologize for the simplicity of this question - I don't know much about HTML elements and I did a search on the forum first.

I just started using the _IETableWriteToArray function in some of my project and I love it because it allows me to easily grab lists and stuff them in an array.  Now I am trying to do the same thing with some HTML that does not use tables.  However, the HTML IDs for the sections containing the data I want to read repeat themselves throughout.  Example (where "foobar" is repeated throughout):

<div id="foobar" style="width: 440px; float: left; padding-left: 10px">DATA<br>MORE DATA<br>MAORE DATA<br>MORE DATA</div>

I know that I can refer to a given element like this:

Local $element = _IEGetObjById($oIE, "foobar")

However, I am wondering what is the best way to grab the values of all the same ID elements and get them into an array? Any guidance would be appreciated.

JFish


Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites



.... maybe using the InnerHTML property

Local $element = _IEGetObjById($oIE, "foobar")
Local $sText = $element.InnerHTML

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

@Chimp -

Thanks, that does help a lot.  It brings back everything including all tags etc but I can parse a lot of that out.  I recently saw a post where someone was using jquery and au3.  They did something like this:

$testValue= $oIE.document.parentWindow.jQuery('#objectID').val()

I don't know much about jquery but I believe that would probably eliminate the need to whittle down the innerhtml that comes back.  Are you familiar with that approach?  Could that be used to get a collection of the values that I am after while ignoring the html? 

EDIT: I also noticed that the :

$element.InnerHTML

Only seems to work for the first element with that ID.  If there is more than one the others seem to be ignored.  Any ideas on that?





			
				


	Edited  by Jfish
	
	

			
		

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites

 

@Chimp -

Thanks, that does help a lot.  It brings back everything including all tags etc but I can parse a lot of that out.  I recently saw a post where someone was using jquery and au3.  They did something like this:

$testValue= $oIE.document.parentWindow.jQuery('#objectID').val()

I don't know much about jquery but I believe that would probably eliminate the need to whittle down the innerhtml that comes back.  Are you familiar with that approach?  Could that be used to get a collection of the values that I am after while ignoring the html? 

 

.. not familiar with jQuery

you could also try with the InnerText property,

 

EDIT: I also noticed that the :

$element.InnerHTML

Only seems to work for the first element with that ID.  If there is more than one the others seem to be ignored.  Any ideas on that?

In an HTML page there should be only one element with a specific ID, in fact a specific ID can be assigned to only a single element

If you see more elements with the same ID maybe is because you are in presence of "frames", that is like if you have more pages in the same page, so, if you want to refer to elements of different pages (frames), you need to get references to single frames first.

have a look to >this link for an "authoritative" explanation :)


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • Seminko
      By Seminko
      I am now able to populate the dropdown menus at https://www.tipcars.com/.
      The dropdowns are dynamic and do not have a Text value, only ids.
      Is there a way to get all the available options from a dropdown?
      $url = "https://www.tipcars.com/" $oIE = _IECreate($url) _IELoadWait($oIE) $oDownloadSamples = _IEGetObjById($oIE, "homepage_vyhl_frm_vozidlo") _IEFormElementOptionSelect($oDownloadSamples, "C") Above code, populates ID 'C' into the 'druh' dropdown, which results in selecting 'užitkové'. 
      Is there a way so I can grab all of the options from the dropdown menu? I could easily grab all the IDs but I am afraid they will change in the future so I would much rather match the text titles and assign the option IDs grabbed from site.
      This is what the options are according to Chrome:
      <select class="w1"id="homepage_vyhl_frm_vozidlo"name="homepage_vyhl_frm_vozidlo"onchange="try{NABIDKA_VOZIDEL_FORMULAR.naplnSelectZnacka('homepage_vyhl_frm');GLOBAL.pocetInzerceHZ('homepage_vyhl_frm','vozidlo');}catch(ex){odeslatJsChybu('formHOMEPAGE onChange 1: ' + ex.message, 'formHomePage onChange 1', -1);}"> <option value="A" style="color: black;">osobní a terénní (56 334)</option> <option value="C" style="color: black;">užitkové (4 333)</option> <option value="D" style="color: black;">nákladní (3 742)</option> <option value="E" style="color: black;">autobusy (56)</option> <option value="F" style="color: black;">obytné (373)</option> <option value="G" style="color: black;">přívěsy (1 179)</option> <option value="J" style="color: black;">motorky (780)</option> <option value="S" style="color: black;">pracovní stroje (605)</option> <option value="L" style="color: black;">ostatní (235)</option></select> Also, this cannot be grabbed by _INetGetSource.
      Thanks
    • Spask
      By Spask
      Hi, I'm trying to find a text value inside of a html.
      This is what the line looks like normally:
      <p id="line1" class> <span class="bot">TEXT HERE</span> </p> The text then changes to a non breaking space:
      <p id="line1" class> <span class="bot">&nbsp;</span> </p> And then it changes back to normal text but it's different every time.
      Can I code this so that it grabs the text every time it changes and has a variable that represents it?
      I currently have this inside of my loop:
      $span = .document.getElementsByTagName("span") For $text In $span If $text.value = "&nbsp;" Then Sleep(50) MsgBox(0,0,0) ;messagebox to test if it can be found, but I don't know how to grab the text EndIf Next The problem is that there are many other lines in the html that have the same span but are called "line3", "line5", etc and the one I need is from "line1".
      I will appreciate if anyone can help with this!
    • electrons
      By electrons
      hi  , hope  you all doing well 
       cant find any elements on the page ?  and the right click mouse dont work too?
      iam trying with more than method , i need help please!!
       

    • ur
      By ur
      I have kept below line to wait for IE to load the site completely and continue.
      _IELoadWait($oIE)
       
      But, the code is continuing without waiting for it and I my execution is failing as the elements are not loaded completely.

       
      Any suggestions for alternate code to wait for the browser to load completely?