Need to capture iframe SRC from html

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
headgeek
Newbie
Posts: 11
Joined: Wed Feb 01, 2017 9:11 pm

Need to capture iframe SRC from html

Post by headgeek » Thu Jan 23, 2025 7:17 pm

Can anyone point me in the direction that will allow me to capture the source url from an iframe? In the example posted below, I am trying to capture the link https://exampleurl.com/sample123

I have tried everything I can think of, but I don't think I'm close.

When I copy the XPATH from chrome dev, I get:
//*[@id="root"]/div/div[2]/div[2]/div/div[2]/iframe/src

The full XPATH option gives me:
#root > div > div.site-router > div:nth-child(2) > div > div:nth-child(2) > iframe

Code: Select all

<iframe class=“document-viewer" src="https://exampleurl.com/sample123" allowfullscreen=""></iframe>

Thank you in advance for any guidance.

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1410
Joined: Sun Nov 03, 2002 3:19 am

Re: Need to capture iframe SRC from html

Post by Dorian (MJT support) » Thu Jan 23, 2025 10:50 pm

Have you tried this..

Code: Select all

ChromeFindElements>session_id,xpath,//[@id='root']/div/div[2]/div[2]/div/div[2]/iframe,arrElementID
Or to just get all the iframes, this..

Code: Select all

ChromeFindElements>session_id,tag name,iframe,arrElementID
Followed by this (of course _1 will just get the first one)..

Code: Select all

ChromeGetElementData>session_id,arrElementID_1,attribute/src,TheSrc

headgeek
Newbie
Posts: 11
Joined: Wed Feb 01, 2017 9:11 pm

Re: Need to capture iframe SRC from html

Post by headgeek » Fri Jan 24, 2025 9:55 pm

THANK YOU SOOOOOO MUCH!

That did not work, but the second part did!

I don't know what was wrong with the XPATH, but I was able to simplify it to

Code: Select all

ChromeFindElements>session_id,xpath,//iframe[@class='document-viewer'],arrElementID
That and using the ChromeGetElementData code that you provided (I did not know about the 'attribute/src' option... I only knew about 'text' and 'value'.)

Code: Select all

ChromeGetElementData>session_id,arrElementID_1,attribute/src,TheSrc
Thank you again for your help.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts