Page 1 of 1

Issue with access to iFrame, webdriver using

Posted: Sat Sep 05, 2020 2:49 pm
by Valeriy777
Hi, I try to use WebDriver endpoint with Ranorex.

All works well when Ranorex works with a simple path, but not when it works with iframe.

It will be better if I provide the example:

Code: Select all

<div id="layout">
    <span id="element1"></span>
    <iframe id="frame1">
        #document
            <html>
                <span id="element2"></span>
            </html>
    </iframe>
</div>
1. I can access to any element Ranorex endpoint using:

Code: Select all

"//span[#'element1']"
"//iframe[#'frame1']//span[#'element2']"
2. I can access the elements that contained outside the iframe WebDriver endpoint using: (including the iframe itself)

Code: Select all

"//span[#'element1']"
"//iframe[#'frame1']"
3. I have the error when I try to get access with WebDriver endpoint to any element that contains inside iframe :

Code: Select all

"//iframe[#'frame1']//span[#'element2']"

How I can use elements in iframe?

Re: Issue with access to iFrame, webdriver using

Posted: Sat Sep 05, 2020 7:27 pm
by Valeriy777
I found solution.

As in the Selenium we need to switch between frames.
I found that WebDriverDocument has the ability to execute frame switching, so I did the following:

Code: Select all

WebDriverDocument wd = WebDriverDocument.FromPatch("//*[1]");
wd.SwitchToFrame("//iframe[@id='frame1']", "xpath");
// wd.SwitchToFrame("frane1", "id"); - also availabled
I used the path "//*[1]" since I didn't know which path I should use in this method. Also, I determined two different paths for WebDriver in my case. I don't know why:

Code: Select all

/dom[@browsername='firefox']
or

Code: Select all

/dom[@domain='myDomain.com']
So I planned to use "/*[1]" in the following.

After that I can manage elements that contained inner iframe:

Code: Select all

WebElement  wl  = "//span[#'element2']";
This is not an ideal solution for my case, since I need switching between endpoints, so I need contain two variants of paths for my WebElements: with "//iframe" in the beginning and without. But it better than nothing.