cbielich Posted February 18, 2018 Share Posted February 18, 2018 (edited) 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 February 18, 2018 by cbielich Link to comment Share on other sites More sharing options...
Danp2 Posted February 18, 2018 Share Posted February 18, 2018 The source code is there. Otherwise, the browser couldn't display the associated elements. What's wrong with using the information you retrieved by "inspecting the element on the page"? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Juvigy Posted February 19, 2018 Share Posted February 19, 2018 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 More sharing options...
Subz Posted February 19, 2018 Share Posted February 19, 2018 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 Danp2 1 Link to comment Share on other sites More sharing options...
cbielich Posted February 20, 2018 Author Share Posted February 20, 2018 Thanks Subz that worked Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now