Jump to content

Is it possible to do a _IEAction($oInput, "click") on innerHTML?


cbielich
 Share

Recommended Posts

I have a page that I need to be able to click on a button, but the class name for that button is only visible with inspecting element on the page and not the source code.

I added

Local $sHTML = $oDoc.documentElement.innerHTML

hoping to be able to use that as the object then change

Local $oInputs = _IETagNameGetCollection($oIE, "span")

to

Local $oInputs = _IETagNameGetCollection($sHTML, "span")

hoping that would work, but of course it did not. Here is my full code.

#include <IE.au3>

$oIE = _IECreate("https://www.example.com/somethinghere/")
Sleep(1000)
$oDoc = _IEDocGetObj ($oIE)
Local $sHTML = $oDoc.documentElement.innerHTML
_IELoadWait($oIE)

$i = 0
while $i <= 10
   Local $oInputs = _IETagNameGetCollection($sHTML, "span")
   For $oInput In $oInputs
      If $oInput.className == "this-class-name" Then _IEAction($oInput, "click")
   Next
   Sleep(2000)
WEnd

Is it possible to click on an element that's only in the innerHTML and not the source code?

Edited by cbielich
Link to comment
Share on other sites

Clicking on the SPAN will not work. You have to find the 'button' or 'div' or 'input' element that is inside it.

So something like

Local $oInputs = _IETagNameGetCollection($sHTML, "span")
   For $oInput In $oInputs
     $oButtons = _IETagNameGetCollection($oInput, "button")
   Next

Of course you can try to get to the element directly by using _IEGetObjByName or _IEGetObjById.

Link to comment
Share on other sites

If a spans is clickable it should work fine for example:

#include <IE.au3>

Local $oIE = _IECreate("https://www.w3.org/TR/2017/NOTE-wai-aria-practices-1.1-20171214/examples/link/link.html", 1)
_IELoadWait($oIE)
Local $oDoc = _IEDocGetObj ($oIE)
Local $oSpans = _IETagNameGetCollection($oDoc, "span")
For $oSpan In $oSpans
    If $oSpan.ClassName = "link3" Then _IEAction($oSpan, "Click")
Next

From my understanding of documentElement, it just reads everything between <html></html> tags, which is what the _IEDocGetObj does so using the same example above I can also get the stylesheet references from the header tag as well.

Local $oIE = _IECreate("https://www.w3.org/TR/2017/NOTE-wai-aria-practices-1.1-20171214/examples/link/link.html", 1)
_IELoadWait($oIE)
Local $oDoc = _IEDocGetObj ($oIE)
Local $oLinks = _IETagNameGetCollection($oDoc, "link")
For $oLink In $oLinks
    If $oLink.href = "https://www.w3.org/StyleSheets/TR/2016/base.css" Then MsgBox(32, "Found Header Link", $oLink.href)
Next

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...