How to switch to iFrame using WebDriver code

Ask general questions here.
User avatar
Aracknid
Posts: 342
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

How to switch to iFrame using WebDriver code

Post by Aracknid » Thu Dec 07, 2017 11:18 pm

Hi,

If I have found an iFrame and stored it in a Ranorex iFrameTag object, and now I want to use Selenium code to switch to the frame, I know I can do this via 4 different ways; By ID, By Name, By Index, and By Selenium WebDriver WebElement.

For the sake of argument, lets suppose the iFrame I have found has no ID or Name.

1) How can I get the index of this frame relative to other frames at the same level in the Dom structure ?

2) Is it possible to convert a Ranorex iFrameTag to a Selenium WebDriver WebElement?

Thanks,

Aracknid

User avatar
Vega
Posts: 109
Joined: Mon Jul 11, 2016 2:15 pm

Re: How to switch to iFrame using WebDriver code

Post by Vega » Fri Dec 08, 2017 7:07 pm

If there is no name or or ID, I have seen Ranorex use the Src attribute for the path:

Code: Select all

/dom[@caption='Tryit Editor v3.5']//iframe[#'iframeResult']/?/?/iframe[@src='https://www.w3schools.com/']
However if none of that is available, it should default to index:

Code: Select all

/dom[@caption='Tryit Editor v3.5']//iframe[#'iframeResult']/?/?/iframe[1]
If you want, you can even force Ranorex to use an index for this item. When you track it, open the path editor in Spy and check the index box under general:
snip.PNG
snip.PNG (11.38 KiB) Viewed 919 times
Now that your Ranorex paths are using index, you know ahead of time what the index will be. As far as converting a Selenium type to a Ranorex type, I don't think this is possible as far as I know unless you convert it property by property yourself. I do know that there is a good amount of overlap between RxPath and XPath so maybe I would start there.

User avatar
Aracknid
Posts: 342
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: How to switch to iFrame using WebDriver code

Post by Aracknid » Mon Dec 11, 2017 8:24 pm

Sorry, I should have been more clear.

My script is based on code using the Ranorex API in Visual Studio. I'm not using Ranorex Studio.

In my code, I already have the iFrame object stored in a variable (I found it using Ranorex code). I'm checking the ID and Name field in code to see if they are blank or not. If they are not blank, I will switch to the frame using the ID or Name. BUT if they are blank, I need to use index or Selenium WebElement. In code (programmatically), can I find out the index of the iFrame relative to other iFrames? IF not, can I convert the iFrame to a Selenium WebElement?

Why am I asking this...? Because (for example) say I have an xPath like this: .//div[#'someID']//iframe//input[#'someotherID']

If I'm looking off the DOM using Ranorex, I can easily find the input. But If I'm running through WebDriver to test against Edge, it will not work since it's within an iFrame and Selenium WebDriver doesn't support work the way Ranorex does. With Selenium, First you need to find the iFrame, then switch to it, and then find the input.

In this simple example, I can find the I frame using Ranorex. But to switch to it, I need to know it's index since it has no ID or Name. Or I need to convert the Ranorex iFrame to a Selenium WebElement if that is possible.

Thanks,

Aracknid


Thanks,

Matt.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to switch to iFrame using WebDriver code

Post by Support Team » Thu Dec 14, 2017 11:13 pm

Hi All,

We are currently working on this issue with the customer via a support ticket and will update this post with new information as it becomes available.

*Update*: This issue was caused by a bug and has been resolved in Ranorex 8.1.0:

Ranorex Release Notes

Thank you for your patience!

-Jon
.
Image