How to access iFrame objects in chrome browser using TestComplete

Originally posted by SK2 on April 22, 2022

I am working in Salesforce application. Here is my scenario:

Opens Salesforce application

Navigate to setup and select one of the user profile

Now, I need to click on the Login button within the profile. However, this button is within an iFrame hence TestComplete unable to identify it.

Originally posted by npaisley on April 22, 2022

Hi SK2!

You can access objects within iFrames by specifying some specific command line flags for Chrome/Edge that disable security restrictions for frames.

Below is the document that will walk you through starting your browser with the required flags;

https://support.smartbear.com/testcomplete/docs/app-testing/web/common-tasks/frames.html

I hope this helps!

Originally posted by SK2 on April 22, 2022

Hi Nick,

As stated in the link above I have entered below line in the command-line, however receiving pop up window as “Failed to Create Data Directory”. I am assuming some permission issue.

“–disable-web-security --user-data-dir="C:\Users\Tester\AppData\Local\Google\Chrome\User Data\Default" --disable-site-isolation-trials”

Originally posted by npaisley on April 22, 2022

Hey SK2,

It does sound like permissions may be the issue here after researching your error;

https://stackoverflow.com/questions/32138828/failed-to-create-data-directory-google-chrome-cannot-read-and-write-its-data-d

Once you are past that error, you may also setup the ‘Call Object Method’ as described in the doc to keep from having to perform this manually on a CLI.

Originally posted by npaisley on April 22, 2022

Hi SK2!

I was able to reproduce your error, there is an extra back slash before your user profile directory that needs to be removed. This extra character causes the same error on my machine.

In the command listed above, let’s remove the back slash after Dir;

Old = "–user-data-dir=****"C:\Users"

New = "–user-data-dir="C:\Users"

I hope this helps!

Originally posted by SK2 on April 22, 2022

Hi Nick,

Thank you for providing above resolution option. After running the command-line by removing the back slash. I received the pop up again, but when clicked on OK, it opened the chrome browser. So I am wondering if this browser session has the security disabled?

Command-line entered:

C:\Program Files\Google\Chrome\Application>chrome.exe --disable-web-security --user-data-dir="C:\Users\Tester\AppData\Local\Google\Chrome\User Data\Default" --disable-site-isolation-trials

Originally posted by npaisley on April 22, 2022

Hey SK2,

Woops, I forgot to mention the trailing backslash at the end as well, just after ‘Default’. Windows doesn’t like slashes like that. Let’s remove that last backslash, with it I do see the same error again.

Old = C:\Users\Tester\AppData\Local\Google\Chrome\User Data\Default\

New = C:\Users\Tester\AppData\Local\Google\Chrome\User Data\Default

Originally posted by SK2 on April 22, 2022

still has the same behavior, I receive the same pop up but when clicked on OK, it opens the chrome browser.

C:\Program Files\Google\Chrome\Application>chrome.exe --disable-web-security --user-data-dir=“C:\Users\Tester\AppData\Local\Google\Chrome\User Data\Default” --disable-site-isolation-trials

Originally posted by npaisley on April 22, 2022

Hey SK2,

I see now what is going on. It looks like you are using the same string from the documentation without altering it with the user account name of your machine.

From the doc = "C:\Users\Tester\AppData\Local\Google\Chrome\User Data\Default"

We need to replace ‘Tester’ with whatever the user account name is in your file path.

Originally posted by SK2 on April 22, 2022

Hi Nick,

That was a good catch, thank you so much. It is now opening the chrome browser successfully through command-line. However, having issues when trying to write a code:

For ex: (‘MyUser’ has the correct value, just replacing here for privacy)

Browsers.Item(“chrome”).RunOptions = “–disable-web-security --user-data-dir=“C:\Users\MyUser\AppData\Local\Google\Chrome\User Data\Default” --disable-site-isolation-trials”;

I get the red cross saying ‘unexpected identifier’, so if I add the back slash before C and after Default then the error goes. However, then the same issue persists with pop up message and opens the browser I guess without security disabled.

Originally posted by npaisley on April 22, 2022

Hey SK2,

Ok, so that’s a step in the right direction!

Those backslashes are going to be required when executing this in the IDE as Python code, we just needed to remove them for basic CLI interaction.

For Python and the TC IDE, you will receive that error if you do not have the indentions correct. I would make sure you’re indenting properly, and add those slashes back.

For instance, this is how I have mine setup and launches Chrome without any popups.

npaisley_0-1650659244725.png

Originally posted by SK2 on April 22, 2022

Hi Nick,

Finally, its working now. I am able to access the object within iFrame. Thank you so much for your help. Actually, I had written the code exact the same way as your above but for some reason it didn’t work earlier and now its working with no change. Now sure. :slightly_smiling_face: So thanks again for your help.

Originally posted by npaisley on April 22, 2022

Hey SK2!

That is awesome to hear, thanks much for letting me know!

Ah yes, the joys of development and code. :slightly_smiling_face:

Happy testing and have a great weekend!

Originally posted by SK2 on April 25, 2022

Hi Nick,

Looks like this issue is not completely resolved. I can open the chrome browser with my code, however I still get the dialog box with Failed to Create Data Directory message while executing my script but once I manually click on OK button then the script continues and enters the URL that open the browser with disabled security version and it performs other actions and access the iFrame object as well.

Browsers.Item(“chrome”).RunOptions = “–disable-web-security --user-data-dir="C:\Users*MyUser*\AppData\Local\Google\Chrome\User Data\Default" --disable-site-isolation-trials”;
Browsers.Item(btChrome).Run(“myAppURL”);

FYI - bold text has real data

Originally posted by SK2 on April 29, 2022

Does anyone has any resolution for my issue above? I am adding my query again below:

I can open the chrome browser to access iFrame with my code, however I still get the dialog box with ‘Failed to Create Data Directory’ message but once I manually click on OK button the script continues and enters the URL that open the browser with disabled security version and it performs other actions and access the iFrame object fine. However, how can I avoid getting the dialog box in the beginning?

Browsers.Item(“chrome”).RunOptions = “–disable-web-security --user-data-dir="C:\Users*MyUser*\AppData\Local\Google\Chrome\User Data\Default" --disable-site-isolation-trials”;
Browsers.Item(btChrome).Run(“myAppURL”);

FYI - bold text has real data

Originally posted by Marsha_R on April 29, 2022

If you google this:

google chrome cannot read and write to its data directory

there are many different suggestions for a fix. I don’t know which one(s) would work for you.

Originally posted by SK2 on April 29, 2022

I tried different options suggested in google but nothing seems be working for me. Please advice.

Originally posted by npaisley on May 02, 2022

Hi SK2,

Sorry to hear you are still having trouble. Unfortunately I’m unable to duplicate this issue on my end.

The code you posted above is not properly formatted to use inside of TestComplete. May you provide a screenshot of the code within TC?

Here is my code that works without any popups;

def iframeTest():
  Browsers.Item["chrome"].RunOptions = "--disable-web-security --user-data-dir=\"C:\\Users\\nicholas.paisley\\AppData\\Local\\Google\\Chrome\\User Data\\Default\" --disable-site-isolation-trials"
  Browsers.Item[btChrome].Run("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe")

Originally posted by SK2 on May 02, 2022

Here is my code:

Browsers.Item(“chrome”).RunOptions = “–disable-web-security --user-data-dir="C:\Users\SK\AppData\Local\Google\Chrome\User Data\Default" --disable-site-isolation-trials”

Browsers.Item(btChrome).Run(“ApplicationURL”)

Originally posted by npaisley on May 02, 2022

Hey SK2,

Well there are couple of issues here, first is that you will need to change all () to and add additional backslashes for formatting. You may reference my code above to see what I mean. Once I did that I was able to launch a browser without issue.

You may want to look into possibly starting TestComplete as an Administrator to see if that will help. If you alter your code to match mine and still receive this error then I would begin to investigate your users permissions on the machine.