[ERROR] - no such frame: element is not a frame when switching to an iFrame

Hi,

I need to verify the text of an element that is inside an iFrame. There is only one iFrame and it has a dynamic ID, name, and src. See the html below:


The element that I need to verify is the one inside the red box. Here’s my code:

String text= "currency"				WebElement iframe = driver.findElement(By.xpath('//*[@id="tradingview_46ed0"]/iframe'));driver.switchTo().frame(iframe)String chart = driver.findElement(By.xpath('//*[@id="chart-area"]/div/div[3]/table/tbody/tr[1]/td[2]/div/div[3]/div[1]')).getText();
if (chart.contains(text)){     println("Currency in the chart is correct.")  }  else{	println(chart)  }

iframe html.png

can you please post whole exception from console?

Hi Andrej,

[ERROR] - Test Cases/TC_142 FAILED because (of) org.openqa.selenium.NoSuchFrameException: no such frame: element is not a frame

my guess is, that even id of parent div is generated … right?
if you are sure that it’s only iframe in system, you can use identification By.tag
or, since id is just another attribute, you can use:
//div[contains(@id,“tradingview”)]//iframe

Hi Andrej,
Thanks for taking time in answering my question. However, I have already tried By.tagname and also tried the xpath you provided. I have also tried getting the iframe id in runtime and use it to switch, but I still get the same error. I don’t understand why it says that the element is not aframe when its tag is iframe.

Hi Nora,

Let me say this first and foremost: I am not an xpath guru. With that out of the way…

I don’t quite see how any xpath expression that begins:

//*[@area"]...

is meant to work with the HTML you posted. As far as I understand it, @foo is meant to look for an element with an attribute named “foo”. I don’t see any element with attribute area in your HTML. Plus, you have a trailing double-quote ("), what’s that meant to do? Is that some weird bit of xpath syntax I’m unaware of?

Lastly, did you try webUI.switchToFrame? (https://docs.katalon.com/display/KD/[WebUI]+Switch+To+Frame) What did that do? Does it complain in the same way?

Russ Thomas said:
Hi Nora,

I don’t quite see how any xpath expression that begins:
//*[@area"]…

@Russ, that looks like forum bug i reported some time ago … it screw up attributes sometimes

@Nora Liza Arcillas
what browser are you using? i did some research on internet and seems like chrome driver have some problems with switching frames

Russ Thomas said:

Hi Nora,

Let me say this first and foremost: I am not an xpath guru. With that out of the way…

I don’t quite see how any xpath expression that begins:

//*[@area"]...

is meant to work with the HTML you posted. As far as I understand it, @foo is meant to look for an element with an attribute named “foo”. I don’t see any element with attribute area in your HTML. Plus, you have a trailing double-quote ("), what’s that meant to do? Is that some weird bit of xpath syntax I’m unaware of?

Lastly, did you try webUI.switchToFrame? (https://docs.katalon.com/display/KD/[WebUI]+Switch+To+Frame) What did that do? Does it complain in the same way?

Hi Russ, I think there was just a mistake when I pasted the xpath. This is my current code:
String chart = driver.findElement(By.xpath(’//*[@id=“chart-area”]/div/div[3]/table/tbody/tr[1]/td[2]/div/div[3]/div[1]’)).getText();

Anyway, yes I’ve already tried WebUI.switchToFrame and it still did not work.

Andrej Podhajský said:

Russ Thomas said:
Hi Nora,

I don’t quite see how any xpath expression that begins:
//*[@area"]…

@Russ, that looks like forum bug i reported some time ago … it screw up attributes sometimes

@Nora Liza Arcillas
what browser are you using? i did some research on internet and seems like chrome driver have some problems with switching frames

Hi Andrej,

Was the issue you’ve posted resolved? If so, could you please share with me the link?
I’m using Chrome, and yes, I’ve also read about the problem in chrome driver. However, I’ve also tried to run my script in Firefox but the same problem occurs.

no, was not resolved

Nora Liza Arcillas said:

Hi Russ, I think there was just a mistake when I pasted the xpath. This is my current code:

String chart = driver.findElement(By.xpath('//*[@id="chart-area"]/div/div[3]/table/tbody/tr[1]/td[2]/div/div[3]/div[1]')).getText();

Anyway, yes I've already tried WebUI.switchToFrame and it still did not work.  

  

instead of @ in xpath use (a) (we will decipher that)

Nora,

Even allowing for the forum mangling the @area string, I still don’t see it in the HTML you

posted.

What happened when you tried switchToFrame?

@Andrej Thanks. See my reply on the forum/xpath issue.

Hi Russ,

This is the xpath of the object inside the iframe that I need to verify and the error when I used switchToFrame of Katalon:

This is the full error message:
[FAILED] - Unable to verify image ‘Object Repository/trade.html/Chart ifRame’ present (Root cause: org.openqa.selenium.NoSuchFrameException: no such frame: element is not a frame

And this is the iFrame:

iframe error.png

iframe xpath.png

Nora,

In the original post dated 9/4/2014 you gave us the screenshot of the target HTML. There I found an

<div id="tradingview_46ed0">  <iframe id="tradingview_302d2" name="tradingview_302d2" ...

In the same post you gave us a XPath like this:

//*[@id="tradingview_46ed0"]/iframe

I suppose these @id value (with alpha-numeric characters 46ed0) were generated dynamically by your WebApp or by JavaScript framework. The value may change every time you make query for the page, don’t they?

If I am right, you should avoid coding the variable portion (‘302d2’ and ‘46ed0’) in your xpath.

I would propose to you an alternative xpath. Try this:

//div[starts-with(@id,"tradingview_")]/iframe

Hi Kazurayam,

The div id is not dynamic. Only the iframe ID, name, and src are dynamic. But I will try your suggestion.

deleted