<div>
<iframe id="cq-cf-frame ">
<iframe id="gen367">
<body spellcheck="false" id="CQrte" style="height: 255px; font-size: 12px; font-family:tahoma,arial,helvetica,sans-serif; background-image: url("/libs/cq/ui/widgets/themes/default/ext/form/text-bg.gif"); background-repeat: repeat-x; background-attachment: fixed;">
<p>4t43t4<br></p>
</body >
</iframe>
</iframe>
</div>
In this scenario there is an iframe
under iframe
. And I have to select the outer iframe
to go to inner iframe
and write in the body which is in the inner iframe
.
Next, I have to come out from the inner iframe
to outer iframe
and click on OK button, (which is in the outer iframe
).
Following is my code
/*Line 1 */ driver.switchTo().frame("cq-cf-frame");
/* 2 */ driver.findElement(By.css("#extdd-9 > div.tblRow > input.edititem").click();
/* 3 */ driver.switchT().Frame("cq-gen379");
/* 4 */ driver.findElement(By.id("CQrte").sendKeys("Tnx");
/* 5 */ selenium.selectFrame("relative=up");
/* 6 */ driver.findElement(By.xpath("//button[text()='OK']")).click();
Following is my problem:
My test code is working fine up to line number 4 i.e. writing into the body, but I want to come out from inner to outer iframe
it says that the element //button[text()='OK']
not found.
I tried with using index, parent, relative, but had no luck.
NOTE: If I don’t select inner frame (cq-gen379). I'm able to click on OK
button.
Selenium Web Driver Handling Frames
It is impossible to click iframe directly through XPath since it is an iframe. First we have to switch to the frame and then we can click using xpath.
driver.switchTo().frame()
has multiple overloads.driver.switchTo().frame(name_or_id)
Here your
iframe
doesn't have id or name, so not for you.driver.switchTo().frame(index)
This is the last option to choose, because using index is not stable enough as you could imagine. If this is your only iframe in the page, try
driver.switchTo().frame(0)
driver.switchTo().frame(iframe_element)
The most common one. You locate your iframe like other elements, then pass it into the method.
driver.switchTo().
defaultContent(); [parentFrame, defaultContent, frame]
XML Test:
Conversion of RC to Web-Driver Java commands. link.
<frame>
is an HTML element which defines a particular area in which another HTML document can be displayed. A frame should be used within a<frameset>
. « Deprecated. Not for use in new websites.