Find Frame name

1,036 views
Skip to first unread message

ARK Satyanarayana Raju

unread,
Apr 22, 2013, 3:07:18 AM4/22/13
to seleniu...@googlegroups.com
Hi,
     Can any one say how to find frame name in selenium webdriver using Java.

Find frame name to the following scenario:
-> Open "http://www.capella.edu/"
-> Click on "Email"
-> Find the frame name of the opened pop up.


Thanks,
Raju

Timur Nurlygayanov

unread,
Apr 22, 2013, 3:18:24 AM4/22/13
to seleniu...@googlegroups.com, rkramakr...@gmail.com
Hi Raju,

You can use Firefox plugins FireBug and FirePath to detect parameters of objects on the pages.
For example, this iframe has the following xpath: .//*[@id='modal-iframe']
and you can use this id 'modal-iframe' in your code.


Regards,
Timur





--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/eT2Q-bKsOGMJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Timur Nurlygayanov

unread,
Apr 22, 2013, 3:22:29 AM4/22/13
to seleniu...@googlegroups.com, rkramakr...@gmail.com
Additionally,

We can use method
WebElement frame = driver.findElement(By.tagName("iframe"));

The detailed information can be found by the following link: http://docs.seleniumhq.org/docs/03_webdriver.jsp


Regards,
Timur

ARK Satyanarayana Raju

unread,
Apr 22, 2013, 4:28:13 AM4/22/13
to seleniu...@googlegroups.com
Hi Timur
     Thanks for u r idea, but it shows error.Can u solve this
//Open the web address and clicl on Email and enter data in pop up.
package Practice_pack_1;

import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class MovetoPopupEnterData {
   
WebDriver driver;
   
public static String latestwindowid;
   
@BeforeTest
   
public void open()
   
{
        driver
=new FirefoxDriver();
       
        driver
.manage().window().maximize();
         driver
.get("http://www.capella.edu/");
   
}
   
@AfterTest
   
public void close()
   
{
        driver
.quit();
   
}
     
   
@Test
   
public void switchtopopupEnterdata() throws InterruptedException
   
{
        driver
.manage().timeouts().implicitlyWait(8, TimeUnit.SECONDS);
        driver
.findElement(By.xpath(".//*[@id='hdr_connect']/ul/li[4]/a")).click();
        driver
.switchTo().frame(driver.findElement(By.xpath(".//*[@id='modal-iframe']")));
       
Thread.sleep(5000);
       
System.out.println("Pop up was found");
        driver
.findElement(By.xpath(".//*[@id='first_name']")).sendKeys("AAAAAAaaaaaaaaaaaaa");
   
}
}

Console:
FAILED: switchtopopupEnterdata
org.openqa.selenium.NoSuchFrameException: Element is not a frame element: DIV
Command duration or timeout: 8.06 seconds
Build info: version: '2.31.0', revision: '1bd294d', time: '2013-02-27 20:53:56'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.7.0_02'
Session ID: ed7988ad-dc2c-47f5-aad7-81a8188f935f
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=firefox, rotatable=false, locationContextEnabled=true, version=17.0.1, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, browserConnectionEnabled=true, nativeEvents=true, webStorageEnabled=true, applicationCacheEnabled=true, takesScreenshot=true}]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

Thanks,
Raju

Emailofvm

unread,
Apr 22, 2013, 4:49:28 AM4/22/13
to seleniu...@googlegroups.com
The other simple way to find frame is, install IDE plugin of Firefox and record the the steps. You will get frame name in that :)



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/ymyZ1v-OlJgJ.

Fakrudeen Shahul

unread,
Apr 22, 2013, 5:09:37 AM4/22/13
to seleniu...@googlegroups.com
check the tag name by driver.findElement(By.xpath(".//*[@id='modal-iframe']")).getTagName() to confirm that the returned element is a frame.

Timur Nurlygayanov

unread,
Apr 22, 2013, 5:25:54 AM4/22/13
to seleniu...@googlegroups.com
You can use the following:

driver.switchTo().frame(driver.findElement(By.xpath("/html/body/div[3]/iframe")));

instead 

driver.switchTo().frame(driver.findElement(By.xpath(".//*[@id='modal-iframe']")));


I tested it and it is works on my laptop.

Emailofvm,
Thanks for your idea, it is the simplest method to determine locators for selenium,
but it is does not work, selenium IDE does not detect the iframe on this page.


Regards,
Timur

ARK Satyanarayana Raju

unread,
Apr 22, 2013, 5:38:55 AM4/22/13
to seleniu...@googlegroups.com
Hi sir,

     Thanks it works fine. How u find

driver.switchTo().frame(
driver.findElement(By.xpath("/html/body/div[3]/iframe")));
Can u say? If possible provide snap shot.

Thanks,
Raju

Timur Nurlygayanov

unread,
Apr 22, 2013, 6:08:14 AM4/22/13
to seleniu...@googlegroups.com
Hi Raju,

To determine this locator I perform the following actions:
1. Install Firefox + FireBug + FirePath
2. Open link http://www.capella.edu/ in Firefox browser
3. Click on 'Email' link.
4. Enable FireBug plugin and find this iframe by mouse click on the popup form.
5. Click right mouse button on the iframe HTML element in FireBug console and select 'Copy xPath'.
The xPath of the element will be copied to clipboard.
The short video with all actions can be downloaded by the following link:


Regards,
Timur


To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/IFYtx5ArorUJ.

ram krishna

unread,
Apr 22, 2013, 7:51:04 AM4/22/13
to seleniu...@googlegroups.com
Thanks a lot for u r replay. Its really awesome.
now i got xpath. My mistake is, i copied same div xpath but u copied next div xpath.

Thanks, 
Raju

ARK Satyanarayana Raju

unread,
Apr 24, 2013, 5:30:47 AM4/24/13
to seleniu...@googlegroups.com
Sir,

I did like what u said. Every thing fine but unable to close that pop up.
Can u give any suggestion

Thanks,
Raju

Gustavo Godoy

unread,
Apr 24, 2013, 8:52:28 AM4/24/13
to seleniu...@googlegroups.com
Hi,

I'm late on this topic, but want to share my 'frame mechanism''...

When interacting with frames, you probably get lost where you are... You switch forward, switch back, etc.

This method helps me. It navigates through frames and when his name matches to where I want to go, then selenium switches...

It selenium backed webdriver, ok?



  public void selectFrame(String frameId)
  {

    selenium.selectFrame("relative=up");
    if (frameId.contains(":"))
    {
      String[] arr = frameId.split(":");
      winName = arr[0];
      frame = arr[1];
      selenium.selectWindow(winName);
      selenium.selectFrame(frame);
    }
    else
    {
      selenium.selectFrame(frameId);

Timur Nurlygayanov

unread,
Apr 24, 2013, 9:43:23 AM4/24/13
to seleniu...@googlegroups.com
Hi,

Gustavo, good idea, thanks for your code example.

Raju, this problem with selenium-focus on the current frame.
After each

driver.switchTo().frame()

function call we should call function

driver.switchTo().defaultContent()

to switch to the main page.

To close this pop up we use the following code:

driver.switchTo().defaultContent();
close_button = driver.findElement(By.xpath("/html/body/div[3]/a"));
close_button.Click();


Regards,
Timur


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/NnkWmGdor_MJ.

Raju

unread,
Apr 24, 2013, 9:46:57 AM4/24/13
to seleniu...@googlegroups.com

ARK Satyanarayana Raju

unread,
Apr 25, 2013, 5:33:08 AM4/25/13
to seleniu...@googlegroups.com
Sir ,

I tried this but it shows error.

//Open the web address and click on Email and enter data in pop up.
 
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class MovetoPopupEnterData {
   
WebDriver driver;
   
public static String latestwindowid;
   
@BeforeTest
   
public void open()
   
{
        driver
=new FirefoxDriver();
       
        driver
.manage().window().maximize();
         driver
.get("http://www.capella.edu/");
   
}
   
@AfterTest
   
public void close()
   
{
        driver
.quit();
   
}
     
   
@Test
   
public void switchtopopupEnterdata() throws InterruptedException
   
{
        driver
.manage().timeouts().implicitlyWait(8, TimeUnit.SECONDS);

        driver
.findElement(By.xpath(".//*[@id='hdr_connect']/ul/li[4]/a")).click();//Xpath of Email

        driver
.switchTo().frame(driver.findElement(By.xpath("/html/body/div[3]/iframe")));

       
Thread.sleep(5000);
       
System.out.println("Pop up was found");
        driver
.findElement(By.xpath(".//*[@id='first_name']")).sendKeys("AAAAAAaaaaaaaaaaaaa");

       
Thread.sleep(2000);
        driver
.switchTo().defaultContent();
       
WebElement close_button = driver.findElement(By.className("/html/body/div[4]/a"));
        close_button
.click();
       
Thread.sleep(5000);
   
}
}

Console:
Pop up was found
FAILED: switchtopopupEnterdata
org.openqa.selenium.WebDriverException: An invalid or illegal string was specified
Command duration or timeout: 16 milliseconds

Build info: version: '2.31.0', revision: '1bd294d', time: '2013-02-27 20:53:56'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.7.0_02'
Session ID: fda5e7be-145a-4963-a76d-442f2da89081

Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=firefox, rotatable=false, locationContextEnabled=true, version=17.0.1, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, browserConnectionEnabled=true, nativeEvents=true, webStorageEnabled=true, applicationCacheEnabled=true, takesScreenshot=true}]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:187)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:307)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByClassName(RemoteWebDriver.java:388)
    at org.openqa.selenium.By$ByClassName.findElement(By.java:371)

Timur Nurlygayanov

unread,
Apr 25, 2013, 7:13:17 AM4/25/13
to seleniu...@googlegroups.com
Hi Raju,

It is my typo mistake, need to change line
WebElement close_button = driver.findElement(By.className("/html/body/div[4]/a"));
to 
WebElement close_button = driver.findElement(By.xpath("/html/body/div[4]/a")); 

Hope this will help.

Regards,
Timur


To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/jS86AwJXSesJ.

Raju

unread,
Apr 25, 2013, 7:59:24 AM4/25/13
to seleniu...@googlegroups.com
Hi

below is the working code:

driver.get("http://www.capella.edu/");
        driver.findElement(By.linkText("Email")).click();
        driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@src='/email-us']")));
Thread.sleep(5000);
        driver.findElement(By.id("first_name")).sendKeys("testing now");


Thanks,
Naga
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/jS86AwJXSesJ.

ARK Satyanarayana Raju

unread,
Apr 25, 2013, 8:05:11 AM4/25/13
to seleniu...@googlegroups.com

Thanks Timur. It works with below code.

WebElement close_button = driver.findElement(By.xpath(".//*[@id='modal-iframe']/a"));
 close_button.click();

Can u explain what is the use of the following method.
driver.switchTo().defaultContent();
Here defaultContent(); means....

Thanks,
Raju
Reply all
Reply to author
Forward
0 new messages