mjolnirmarkiv

getElementsByClassName doesn't work

3 posts in this topic

#1 ·  Posted (edited)

Hi!

Does anyone have any idea why Test() returns 0, while Test2() returns 1?

#include <IE.au3>

MsgBox(0, "", Test() & " " & Test2())

Func Test()
    Local $oHTML = ObjCreate("HTMLFILE")

    $oHTML.body.innerHTML = FileRead("Test.html")

    Return IsObj($oHTML.getElementsByClassName("example"))
EndFunc

Func Test2()
    Local $oIE = _IEAttach("", "instance", 1)

    Return IsObj($oIE.document.getElementsByClassName("example"))
EndFunc

Sample Test.html I open in IE before testing:

<!DOCTYPE html>
<html>
    <body>
        <p class="example"></p>
        <div class="example"></div>
    </body>
</html>

I'm receiving html text in a response to http request, I need to parse it fast and easy, getElementsByClassName would have been ideal. I'm using 3.3.12.0 version.

Edited by mjolnirmarkiv

Share this post


Link to post
Share on other sites



Wrote something a couple of days ago to get class names:

 

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

  • Similar Content

    • 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?
       
    • ur
      By ur
      We can select elements in IE using their IDs as below.
      Local $oDiv = _IEGetObjById($oIE, "x-auto-16-input") But to one button in the webpage, there is no ID to it.
      In selenium we have option to select this element using the CssSelector and clicked the button using below code in c# selenium.
      driver.FindElement(By.CssSelector("button.x-btn-text")).Click(); What is the alternative for this in AUtoIT?