Vitaliy4us Posted October 20, 2019 Share Posted October 20, 2019 (edited) I am trying to get access to iframe elements using IE.au3. Local $oIE = _IECreate($URL) Local $oDoc = _IEDocGetObj($oIE) Local $x = $oDoc.getElementsByTagName("iframe").item(0).contentWindow but I get an error "The requested action with this object has failed." on this step Local $x1 = x.document HTML looks like this <html> <head>...</head> <body> <iframe> #document <html> <head>...<head> <body>....</body> </html> </iframe> </body> </html> An this is an example I found on https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/contentWindow var x = document.getElementsByTagName("iframe")[0].contentWindow; //x = window.frames[0]; x.document.getElementsByTagName("body")[0].style.backgroundColor = "blue"; // this would turn the 1st iframe in document blue. What is the reason and how can I get access to the DOM elements located in iframe Edited October 20, 2019 by Vitaliy4us error Link to comment Share on other sites More sharing options...
Vitaliy4us Posted October 20, 2019 Author Share Posted October 20, 2019 Maybe the reason is that "Because of security reasons, the contents of a document can be accessed from another document only if the two documents are located in the same domain" ? ( https://www.w3schools.com/jsref/prop_frame_contentdocument.asp ). But anyway the question remains the same: how can I get access to the DOM elements located in iframe Link to comment Share on other sites More sharing options...
Danp2 Posted October 20, 2019 Share Posted October 20, 2019 Have you tried with _IEFrameGetObjByName? If that doesn't work, then you will likely need to open the frame in a new tab to gain access to it's contents. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Vitaliy4us Posted October 20, 2019 Author Share Posted October 20, 2019 (edited) 3 hours ago, Danp2 said: Have you tried with _IEFrameGetObjByName? If that doesn't work, then you will likely need to open the frame in a new tab to gain access to it's contents. The element name is really huge to be used: <iframe id="com.thed.zephyr.je__viewissue-teststep__18d264ab" name="{"extension_id":"com.thed.zephyr.je__viewissue-teststep__18d264ab","api":{"_globals":{"request":{"args":["a","e"],"returnsPromise":false}},"messages":{"clear":{"args":["a"],"returnsPromise":false},"onClose":{"args":["a","c"],"returnsPromise":false},"generic":{"constructor":{"args":["c","b","d","e"],"returnsPromise":false}},"error":{"constructor":{"args":["c","b","d","e"],"returnsPromise":false}},"warning":{"constructor":{"args":["c","b","d","e"],"returnsPromise":false}},"success":{"constructor":{"args":["c","b","d","e"],"returnsPromise":false}},"info":{"constructor":{"args":["c","b","d","e"],"returnsPromise":false}},"hint":{"constructor":{"args":["c","b","d","e"],"returnsPromise":false}}},"flag":{"create":{"constructor":{"args":["a","b"],"returnsPromise":false},"close":{"args":[],"returnsPromise":false}}},"dialog":{"create":{"constructor":{"args":["a","c"],"returnsPromise":false}},"close":{"args":["a","c"],"returnsPromise":false},"getCustomData":{"args":["a"],"returnsPromise":false},"getButton":{"constructor":{"args":["a","c"],"returnsPromise":false},"enable":{"args":[],"returnsPromise":false},"disable":{"args":[],"returnsPromise":false},"toggle":{"args":[],"returnsPromise":false},"isEnabled":{"args":["a"],"returnsPromise":false},"trigger":{"args":["a"],"returnsPromise":false},"hide":{"args":[],"returnsPromise":false},"show":{"args":[],"returnsPromise":false},"isHidden":{"args":["a"],"returnsPromise":false}},"createButton":{"constructor":{"args":["a","c"],"returnsPromise":false}}},"inlineDialog":{"hide":{"args":["a"],"returnsPromise":false}},"env":{"getLocation":{"args":["a"],"returnsPromise":false},"resize":{"args":["a","c","b"],"returnsPromise":false},"sizeToParent":{"args":[],"returnsPromise":false},"hideFooter":{"args":["a"],"returnsPromise":false}},"events":{"emit":{"args":["a"],"returnsPromise":false},"emitPublic":{"args":["a"],"returnsPromise":false}},"_analytics":{"trackDeprecatedMethodUsed":{"args":["a","c"],"returnsPromise":false}},"scrollPosition":{"getPosition":{"args":["a"],"returnsPromise":false},"setVerticalPosition":{"args":["a","c"],"returnsPromise":false}},"dropdown":{"create":{"args":["a","c"],"returnsPromise":false},"showAt":{"args":["a","c","b","d"],"returnsPromise":false},"hide":{"args":["a"],"returnsPromise":false},"itemDisable":{"args":["a","c"],"returnsPromise":false},"itemEnable":{"args":["a","c"],"returnsPromise":false}},"cookie":{"save":{"args":["a","d","e"],"returnsPromise":false},"read":{"args":["a","d"],"returnsPromise":false},"erase":{"args":["a"],"returnsPromise":false}},"history":{"_registerWindowListeners":{"args":[],"returnsPromise":false},"back":{"args":["a"],"returnsPromise":false},"forward":{"args":["a"],"returnsPromise":false},"go":{"args":["a"],"returnsPromise":false},"getState":{"args":["a","g"],"returnsPromise":false},"pushState":{"args":["a","g"],"returnsPromise":false},"replaceState":{"args":["a","g"],"returnsPromise":false}},"navigator":{"getLocation":{"args":["a"],"returnsPromise":false},"go":{"args":["a","b","c"],"returnsPromise":false},"reload":{"args":[],"returnsPromise":false}},"user":{"getUser":{"args":["a"],"returnsPromise":false},"getCurrentUser":{"args":["a"],"returnsPromise":false},"getTimeZone":{"args":["a"],"returnsPromise":false},"getLocale":{"args":["a"],"returnsPromise":false}},"context":{"getToken":{"args":["a"],"returnsPromise":true},"getContext":{"args":["a"],"returnsPromise":true}},"jira":{"refreshIssuePage":{"args":[],"returnsPromise":false},"updateIssueGlance":{"args":["a","b"],"returnsPromise":false},"getWorkflowConfiguration":{"args":["b"],"returnsPromise":false},"_submitWorkflowConfigurationResponse":{"args":["a","c"],"returnsPromise":false},"isDashboardItemEditable":{"args":["b"],"returnsPromise":false},"openCreateIssueDialog":{"args":["e","b"],"returnsPromise":false},"setDashboardItemTitle":{"args":["b","c"],"returnsPromise":false},"openDatePicker":{"args":["a","c"],"returnsPromise":false},"initJQLEditor":{"args":[],"returnsPromise":false},"showJQLEditor":{"args":["a","d"],"returnsPromise":false}},"dropdownList":{"create":{"constructor":{"args":["a"],"returnsPromise":false},"showAt":{"args":["a","b","l"],"returnsPromise":false},"setItems":{"args":["a","b"],"returnsPromise":false},"hide":{"args":[],"returnsPromise":false},"moveUp":{"args":[],"returnsPromise":false},"moveDown":{"args":[],"returnsPromise":false},"query":{"args":["a"],"returnsPromise":false},"select":{"args":[],"returnsPromise":false},"isVisible":{"args":["a"],"returnsPromise":false},"getSelected":{"args":["a"],"returnsPromise":false},"onHide":{"args":[],"returnsPromise":false},"onSelect":{"args":[],"returnsPromise":false}}}},"origin":"https://herobrands.atlassian.net","options":{"history":{"state":""},"uniqueKey":"com.thed.zephyr.je__viewissue-teststep","origin":"https://prod-play.zephyr4jiracloud.com","hostOrigin":"https://herobrands.atlassian.net","moduleType":"webPanels","moduleLocation":"atl.jira.view.issue.left.context","isFullPage":false,"autoresize":true,"user":{"timeZone":"Europe/Zaporozhye"},"productContext":{"project.key":"BP2","project.id":"10003","issue.id":"11758","issue.key":"BP2-1073","issuetype.id":"10008"},"structuredContext":{"license":{"active":true},"jira":{"issue":{"issuetype":{"id":"10008"},"key":"BP2-1073","id":"11758"},"project":{"key":"BP2","id":"10003"}}},"contextJwt":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI1Y2ZkNzNiOWJmZWE4NDBjNWRkMThhYzgiLCJpc3MiOiJiMjQ1MGU0Yi0xYzFkLTNhNjMtOWExZi1lOGI4ZTdmMzcxZjQiLCJjb250ZXh0Ijp7ImxpY2Vuc2UiOnsiYWN0aXZlIjp0cnVlfSwiamlyYSI6eyJpc3N1ZSI6eyJpc3N1ZXR5cGUiOnsiaWQiOiIxMDAwOCJ9LCJrZXkiOiJCUDItMTA3MyIsImlkIjoiMTE3NTgifSwicHJvamVjdCI6eyJrZXkiOiJCUDIiLCJpZCI6IjEwMDAzIn19fSwiZXhwIjoxNTcxNTg0OTAwLCJpYXQiOjE1NzE1ODQwMDB9.eONgeHeGW2cY7oDPS7pDMJ-qeMbNdQQUW0TvjcZ6Ep0","contextPath":"","width":"70%","targets":{"env":{"resize":"both"}},"contentClassifier":"","globalOptions":{"crev":"1.2.29"}}}" src="https://prod-play.zephyr4jiracloud.com/connect/public/html/teststeps?projectId=10003&issueId=11758&isBdd=false&xdm_e=https%3A%2F%2Fherobrands.atlassian.net&xdm_c=channel-com.thed.zephyr.je__viewissue-teststep&cp=&xdm_deprecated_addon_key_do_not_use=com.thed.zephyr.je&lic=active&cv=1.532.0&jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI1Y2ZkNzNiOWJmZWE4NDBjNWRkMThhYzgiLCJxc2giOiIxODBhYmJkMGQ2MzlmZThjNzVmOTY2YWE4YjQ5ZWQ5NDY3N2VkMzRiMTMyZWYxOTM1MDhjMjU5Zjc1ZWM0NjIyIiwiaXNzIjoiYjI0NTBlNGItMWMxZC0zYTYzLTlhMWYtZThiOGU3ZjM3MWY0IiwiY29udGV4dCI6e30sImV4cCI6MTU3MTU4NDkwMCwiaWF0IjoxNTcxNTg0MDAwfQ.NhMHDaN0MMzVzkwAOsCdRyl5DuoYY7TehHEdEfPVKcM" width="70%" referrerpolicy="no-referrer" class="ap-iframe" style="width: 100%; height: 790px;"></iframe> But I tried Local $x = _IEFrameGetCollection ($oIE).item(0) $x.document The same problem in $x.document Edited October 20, 2019 by Vitaliy4us Link to comment Share on other sites More sharing options...
Danp2 Posted October 20, 2019 Share Posted October 20, 2019 2 hours ago, Vitaliy4us said: The element name is really huge to be used Then use _IEGetObjById or _IEFrameGetCollection, like this -- $oFrame = _IEFrameGetCollection($oIE, 0) ; change 0 to correct index # Once you have a valid reference to the frame, use $oFrame with the standard _IE* commands the same way you would $oIE. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Vitaliy4us Posted October 20, 2019 Author Share Posted October 20, 2019 11 minutes ago, Danp2 said: Then use _IEGetObjById or _IEFrameGetCollection, like this -- $oFrame = _IEFrameGetCollection($oIE, 0) ; change 0 to correct index # Once you have a valid reference to the frame, use $oFrame with the standard _IE* commands the same way you would $oIE. Yes I tried them all. There is not a problem to get iframe element itself. The probblem is to get its document property for dealing with its DOM. As you can see I got the iframe element itself by different ways but for any of them I had the same issue while trying to use $oElement.document command Link to comment Share on other sites More sharing options...
Danp2 Posted October 20, 2019 Share Posted October 20, 2019 Run this code (directly from the help file) and show us the output -- Local $oFrames = _IEFrameGetCollection($oIE) Local $iNumFrames = @extended Local $sTxt = $iNumFrames & " frames found" & @CRLF & @CRLF Local $oFrame = 0 For $i = 0 To ($iNumFrames - 1) $oFrame = _IEFrameGetCollection($oIE, $i) $sTxt &= _IEPropertyGet($oFrame, "innertext") & @CRLF Next MsgBox($MB_SYSTEMMODAL, "Frames Info", $sTxt) Also, can you provide the main URL you're trying to access? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Vitaliy4us Posted October 21, 2019 Author Share Posted October 21, 2019 (edited) 8 hours ago, Danp2 said: Run this code (directly from the help file) and show us the output -- Local $oFrames = _IEFrameGetCollection($oIE) Local $iNumFrames = @extended Local $sTxt = $iNumFrames & " frames found" & @CRLF & @CRLF Local $oFrame = 0 For $i = 0 To ($iNumFrames - 1) $oFrame = _IEFrameGetCollection($oIE, $i) $sTxt &= _IEPropertyGet($oFrame, "innertext") & @CRLF Next MsgBox($MB_SYSTEMMODAL, "Frames Info", $sTxt) Also, can you provide the main URL you're trying to access? Hello, Danp2. Thank you very much for a lot of your help. I have tried your code. But this time I got an error inside the ie.au3 "C:\Program Files (x86)\AutoIt3\Include\IE.au3" (2294) : ==> The requested action with this object has failed.: $oTemp = $oObject.document.body $oTemp = $oObject^ ERROR Unfortunatelly I am not able to provide you with the base URL because it is a company's project. But this is a general Jira ticket or to be more correct Zephyr Test Case. So my goal is to retreave test steps from the test case. I am able to deal with the DOM of the page by creating the correspondent object: Local $oDoc = _IEDocGetObj($oIE) But the DOM does not include any element located inside iframes. But the problems is that all the elements I need (which actually are test steps) are inside the iframe. Edited October 21, 2019 by Vitaliy4us Link to comment Share on other sites More sharing options...
Danp2 Posted October 21, 2019 Share Posted October 21, 2019 Sorry.... but I'm out of ideas beyond my earlier suggestion to open the iframe in a new tab and then access the elements from there. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Vitaliy4us Posted October 21, 2019 Author Share Posted October 21, 2019 55 minutes ago, Danp2 said: Sorry.... but I'm out of ideas beyond my earlier suggestion to open the iframe in a new tab and then access the elements from there. I tried to do this after you suggested it for the first time (as I can see the URL is the src value from the snippet above?). Unfortunately the rendered page does not contain the steps of the test case I am trying to retrieve... But anyway thanks a lot. 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