Reputation: 371
I want to select a element of iframe which is located with in a popup window. I am able go inside popup window but not able to locate iframe. Below is html code of popup window.
<html>
<head></head>
<body>
<iframe width="100%" height="100%" border="0" src="/some/url.do?parameter=getData">
<html>
.
.
<table id="ec_table" class="tableRegion" width="20%" cellspacing="1" cellpadding="2"
border="0">
<tr class="even">
<td>
<input type="radio" value="173" name="hier_data_id">
</td>
</tr>
.
.
</html>
</iframe>
</body>
</html>
Here I want to click Radio button which is located inside iframe. I used below code to switch with in iframe but it is not switching to iframe.
driver.switchTo().frame(myD.findElement(By.tag("iframe")));
As iframe doesn't have id, i'm finding difficulty locate elements inside iframe.
Does anyone know how I could do it..?
Thanks in advance.
Upvotes: 7
Views: 16686
Reputation: 1
here are the code for selecting the iFrame and enter text "Test data"
$x = $I->grabAttributeFrom('//iframe', 'id');
$I->switchToIframe($x);
$I->fillField('#tinymce', 'Test data');
$I->switchToWindow();`
If you have two iFrame one after another You can switch through this function
$I->switchToWindow();
Upvotes: 0
Reputation: 2461
//iframe[@src="/some/url.do?parameter=getData"]
But this might be a timing & loading issue. So you might be trying to write/read/interact with the iframe before the content has loaded. Try checking for the element before selecting it. And wait if it's not present.
Upvotes: 0
Reputation: 1436
You can switch to a frame by its index . Try the following:
//go to popup
//switch to the first frame , assuming there's only one frame with no id or name
driver.switchTo().frame(0);
driver.findElement(By.name("hier_data_id")).click();
Upvotes: 6