Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to locate iframe in Selenium Webdriver(java)

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.

like image 617
chivas_hvn Avatar asked Aug 08 '12 14:08

chivas_hvn


1 Answers

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();
like image 139
StatusQuo Avatar answered Nov 05 '22 00:11

StatusQuo