Forum Discussion

kaiiii's avatar
kaiiii
Regular Contributor
5 years ago

Handle Iframe

Facing problem with iFrames

I have Iframe id but Not able to find path for internal element of an Iframe where I need to perform click event. How can can i do the same.

while performing inspect on browser I can see tthe path for internal element.

 

is it right to create object for that Iframe by using Name mapping and then use findchildXpath method on that object and provide xpath for all webelement that need to perform ?

  • Hi kaiiii,

    There are some things you should be aware of when accessing objects inside iframe. They are listed in the Considerations for Web Testing help article. Let me quote them here:

     

    • With the default security settings Chrome follows the same-origin policy and does not allow cross-origin interaction. Because of this, TestComplete cannot access the contents of cross-origin framesets (when a host of an HTML frame differs from the host of the parent page). To test the contents of such framesets, you need to open the contained frame as a separate web page or launch the Chrome application with the following command-line switches:

      --disable-web-security (for all Chrome versions)

      --user-data-dir=<ProfilePath> (for all Chrome versions)

      --disable-site-isolation-trials (for Chrome version 70 and later)

      The same-origin policy also applies to framesets displaying local files. By default, the local files are considered to belong to different origins and not allowed to access one from another. To solve the latter issue, you can launch the Chrome application with the --allow-file-access-from-files command-line switch.

      The --disable-web-security, --disable-site-isolation-trials and --allow-file-access-from-files command-line switches impair the browser security. We do not recommend using these switches unless required by your testing needs.
    • To execute the JavaScript eval function on a web page frame in Chrome, you need to use a specific syntax that includes the frame ID. See Executing JavaScript in Frames in Google Chrome.


    Does it help?

  • Hi,

    I dont use namemapping so I might not be of help there but I figured out a way to identify iframe objects with this 

    function LaunchBrowser()

    {

        Browsers.Item(bName).RunOptions = "--disable-web-security --disable-site-isolation-trials --user-data-dir"

        Browsers.Item(bName).Run(YourUrl);

       

    }

    • kaiiii's avatar
      kaiiii
      Regular Contributor

      Hi Reshail 

      Thanks for reply.

      I had do the same and it's not working . still facing same problem.

       

      like

      Set IframeId = Aliases.browser.frameid ..(frame object as per namemapping)

      and below are few buttons that need to click.

       

      authorized 

      not authorized

      attemps

       

      but I am not able to perform object spy on that particular button not able to get path for that particular button

      How can I do the same.

      I had also try

      IframeId.FindChildByXpath(".....................authorized path here..........")

      but it's not working.

      • Reshail's avatar
        Reshail
        Contributor

        Which browser are you using? Have you tried it with Firefox?