Unable to select iframe with selectFrame using webdriver

1,667 views
Skip to first unread message

Douglas Pennington

unread,
Sep 23, 2011, 1:29:46 PM9/23/11
to Selenium Users
Hey,

I'm in a situation where I need to use XPATH when selecting elements
for my web application. The elements all have dynamic ids, and XPATH
currently is the only solution I've found. My dilemia is there are
a lot of IFRAMES setup in the application I'm testing. I've been
told that I need to select the iframe first, before clicking on an
element that is further down the DOM tree.
My code looks like

public static void main(String[] args) //throws IOException
{


final String sBaseUrl = "http://oberon/";
//DefaultSelenium oDefaultSelenium = new
DefaultSelenium(sServerHost, iServerPort, sBrowserType, sBaseUrl);


//For WebDriver
WebDriver iedriver = new InternetExplorerDriver();
DefaultSelenium oDefaultSelenium = new
WebDriverBackedSelenium(iedriver,sBaseUrl);

WebDriver driver = ((WrapsDriver)
oDefaultSelenium).getWrappedDriver();

oDefaultSelenium.open("http://oberon/BullhornStaffing/
BHlogin.cfm");

oDefaultSelenium.type("username", "ddonathan");
oDefaultSelenium.type("password", "0");
oDefaultSelenium.click("//input[@value='Login']");

boolean bLoopAgain = true;
int iLoopCount = 0;

WebElement element = driver.findElement(By.xpath("//
table[@id='bhMenuContainer']/tbody/tr/td/div/div/table/tbody/tr/td"));
element.click();

Common.threadsleep(5000);

//Activity Center
driver.findElement(By.xpath("//table[@id='bhMenuContainer']/tbody/tr/
td/div/div[2]/div[2]/table/tbody/tr[7]/td[2]")).click();
String sTitle = oDefaultSelenium.getText("id=bh_root");
while (bLoopAgain) {


if (sTitle.indexOf("Activity Center")>=0){
System.out.println("In Activity Center");
//Test AC item expansion
//first AC e-mail


Common.threadsleep(5000);

//oDefaultSelenium.selectWindow("");

//
********Problem area **************************
oDefaultSelenium.selectFrame("index=1");

//
******************************************

//This allows me to click on the record itself!
oDefaultSelenium.clickAt("//html/body/div/div", "1,1");


Throws the following:

Exception in thread "main"
com.thoughtworks.selenium.SeleniumException: No frame found (WARNING:
The server did not provide any stacktrace information); duration or
timeout: 51 milliseconds
Build info: version: '2.6.0', revision: '13840', time: '2011-09-13
14:56:25'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1',
java.version: '1.6.0_16'
Driver info: driver.version: RemoteWebDriver
at
org.openqa.selenium.internal.seleniumemulation.Windows.selectFrame(Windows.java:
85)
at
org.openqa.selenium.internal.seleniumemulation.SelectFrame.handleSeleneseCommand(SelectFrame.java:
31)
at
org.openqa.selenium.internal.seleniumemulation.SelectFrame.handleSeleneseCommand(SelectFrame.java:
1)
at
org.openqa.selenium.internal.seleniumemulation.SeleneseCommand.apply(SeleneseCommand.java:
33)
at
org.openqa.selenium.internal.seleniumemulation.Timer.run(Timer.java:
39)
at
org.openqa.selenium.WebDriverCommandProcessor.execute(WebDriverCommandProcessor.java:
265)
at
org.openqa.selenium.WebDriverCommandProcessor.doCommand(WebDriverCommandProcessor.java:
195)
at
com.thoughtworks.selenium.DefaultSelenium.selectFrame(DefaultSelenium.java:
382)
at BHTester.Activity_Center.AC_Verification(Activity_Center.java:234)
at BHTester.mainSanityTest.main(mainSanityTest.java:39)

When I use MS: Developer tools, or Debug bar, I see the IFRAME (There
are two of them). I'm selecting an index of 1 since it is the 2nd
frame I want.

If I try the selectFrame code using Selenium RC1, I get no error
(However, I'm still unable to click on the element).


Any ideas?

Luke Inman-Semerau

unread,
Sep 23, 2011, 1:41:44 PM9/23/11
to seleniu...@googlegroups.com
sounds like a potential bug in the WebDriverBackedSelenium...

Since you have the WebDriver, you can convert that line to the new API:

driver.switchTo().frame(driver.findElements(By.tagName("iframe")).get(0));


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.


Luke Inman-Semerau

unread,
Sep 23, 2011, 1:42:09 PM9/23/11
to seleniu...@googlegroups.com
.get(1)   for the second one :)

Douglas Pennington

unread,
Sep 23, 2011, 2:46:25 PM9/23/11
to Selenium Users
Okay, that workds! Thank you.

However, when I go to run this line

driver.findElement(By.xpath("//html/body/div/div")).click();

I'm getting element not found.

If I go back one level in the DOM
driver.findElement(By.xpath("//html/body/div")).click();

I'm able to click. Any idea on why going down on level down the tree
would not find the element? I'm trying to navigate down to a span
tag that has
a class of class="mostRecentItemArrow toggleClosed"

I'd like to show someone the DOM from Debug bar, but unfortunately
can't attach screenshots in this group.

On Sep 23, 1:42 pm, Luke Inman-Semerau <luke.seme...@gmail.com> wrote:
> .get(1)   for the second one :)
>
> On Fri, Sep 23, 2011 at 10:41 AM, Luke Inman-Semerau <luke.seme...@gmail.com
> >> org.openqa.selenium.internal.seleniumemulation.Windows.selectFrame(Windows.­java:
> >> 85)
> >>        at
>
> >> org.openqa.selenium.internal.seleniumemulation.SelectFrame.handleSeleneseCo­mmand(SelectFrame.java:
> >> 31)
> >>        at
>
> >> org.openqa.selenium.internal.seleniumemulation.SelectFrame.handleSeleneseCo­mmand(SelectFrame.java:
> >> 1)
> >>        at
>
> >> org.openqa.selenium.internal.seleniumemulation.SeleneseCommand.apply(Selene­seCommand.java:
> >> 33)
> >>        at
> >> org.openqa.selenium.internal.seleniumemulation.Timer.run(Timer.java:
> >> 39)
> >>        at
>
> >> org.openqa.selenium.WebDriverCommandProcessor.execute(WebDriverCommandProce­ssor.java:
> >> 265)
> >>        at
>
> >> org.openqa.selenium.WebDriverCommandProcessor.doCommand(WebDriverCommandPro­cessor.java:
> >> 195)
> >>        at
>
> >> com.thoughtworks.selenium.DefaultSelenium.selectFrame(DefaultSelenium.java:
> >> 382)
> >>        at
> >> BHTester.Activity_Center.AC_Verification(Activity_Center.java:234)
> >>        at BHTester.mainSanityTest.main(mainSanityTest.java:39)
>
> >> When I use MS: Developer tools, or Debug bar, I see the IFRAME  (There
> >> are two of them).   I'm selecting an index of 1 since it is the 2nd
> >> frame I want.
>
> >> If I try the selectFrame code using Selenium RC1,  I get no error
> >> (However, I'm still unable to click on the element).
>
> >> Any ideas?
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Selenium Users" group.
> >> To post to this group, send email to seleniu...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> selenium-user...@googlegroups.com.
> >> For more options, visit this group at
> >>http://groups.google.com/group/selenium-users?hl=en.- Hide quoted text -
>
> - Show quoted text -

Saradaprasad Rao

unread,
Jul 25, 2013, 5:07:48 AM7/25/13
to seleniu...@googlegroups.com

Hi Douglas Pennington ,

You can try any  code shown below.

1)selenium.selectFrame("xpath=//iframe[contains(@title,'Rich text editor')]");

or
selenium.selectFrame("relative=up");
or
selenium.selectFrame("relative=top");
or
driver.switchTo().frame(driver.findElements(By.tagName("iframe").get(0));
or
driver.switchTo().frame("frame1");
Reply all
Reply to author
Forward
0 new messages