Element not found when there is an IFRAME in the XPATH.

6,527 views
Skip to first unread message

Douglas Pennington

unread,
Sep 6, 2011, 10:48:56 AM9/6/11
to Selenium Users
Hello,

I'm trying to automate our testing using Selenium RC (selenium-server-
standalone-2.0b2.jar). I'm writing my code in JAVA.
The situation is this:
Our application run ColdFusion. The ColdFusion app renders html to
display pages on the fly. I've had success using .clickAt() method to
click on objects. I'm clicking by ID of individual elements (menus,
buttons, etc). However, the ID for these objects is dynamic. To work
around it, I'm building out XPATH to get at these objects. The issue
I'm running into is that some objects, menus for example, I'll get the
XPATH and run my script. I get an error that it can't find the
element, and returns my XPATH. Other XPATHs to objects work. I
discovered the culprit is the paths/elements that don't work. Have
IFRAME in the path.

So at this point, I tried implementing the following code at:
http://www.testingexcellence.com/accessing-iframe-data-with-selenium-rc/,
which returns TRUE that it is able to verify that the menu text I'm
searching for is there, but I'm still unable to click that paticular
menu option or any other object that sits under and IFRAME.

I'm new to Selenium, and if anyone has any guidance as to a solution
around this issue, I'd deeply appreciate it.

Thank you.

Mark Collin

unread,
Sep 6, 2011, 11:50:39 AM9/6/11
to seleniu...@googlegroups.com
You have to switch to the iFrame before you can interact with elements held
within it.

Selenium 2 Implementation

WebElement iframe = driver.findElement(By.xpath("//iframe"));
driver.switchTo().frame(iframe);
//do stuff

Selenium 1 Implementation

selenium.selectFrame("//iframe");
//do stuff

Hello,

Thank you.

--
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.


--
This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

If you have received this email in error please notify postm...@ardescosolutions.com

Douglas Pennington

unread,
Sep 8, 2011, 9:42:29 AM9/8/11
to Selenium Users
Thanks for the reply Mark.

I'm using the Selenium 1 implementation. I'm trying to select an
item on a menu (in class TopNavMenuContainer) The menu Desktop I'm
able to click on by ID, since its ID doesn't change. Under menu
Desktop is an item Activity Center. Activity Center id is dynamic.
So I'm trying to use XPATH to click on this element

I have the following:

oDefaultSelenium.selectFrame("//iframe");
oDefaultSelenium.clickAt("/div/div/table/div/div/div/table/tbody/tr/
td", "1,1");

Which returns Element Not Found

I've tried replacing the XPATH with

oDefaultSelenium.clickAt("//td[contains(text(), 'Activity Center')]",
"1,1");

Again Element Not Found.

I've even tried selecting the Frame by ID then using XPATH or looking
at the text, and no avail.
> For more options, visit this group athttp://groups.google.com/group/selenium-users?hl=en.
>
> --
> This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.
>
> If you have received this email in error please notify postmas...@ardescosolutions.com- Hide quoted text -
>
> - Show quoted text -

Krishnan Mahadevan

unread,
Sep 8, 2011, 9:47:18 AM9/8/11
to seleniu...@googlegroups.com
Douglas,
Are you trying this on Selenium 2.5.0 ? Coz I happened to notice you mentioning that you were using 2.0b2.jar.


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

Douglas Pennington

unread,
Sep 8, 2011, 11:42:01 AM9/8/11
to Selenium Users
I believe I'm using the Selenium 1 implementation. I haven't upgraded
to Selenium2, and not sure if doing so if going to solve my issue.


On Sep 8, 9:47 am, Krishnan Mahadevan
> >http://groups.google.com/group/selenium-users?hl=en.- Hide quoted text -

Luke Inman-Semerau

unread,
Sep 8, 2011, 1:32:40 PM9/8/11
to seleniu...@googlegroups.com
The 2.5.0 release contains both the RC API and WebDriver API

It is a misnomer to say Selenium2 API since it includes both.

-Luke

Douglas Pennington

unread,
Sep 8, 2011, 1:55:03 PM9/8/11
to Selenium Users
Hey Mark,

You're code snippet

WebElement iframe = driver.findElement(By.xpath("//iframe"));
driver.switchTo().frame(iframe);

What is "driver" defined as?

On Sep 8, 1:32 pm, Luke Inman-Semerau <luke.seme...@gmail.com> wrote:
> The 2.5.0 release contains both the RC API and WebDriver API  
>
> It is a misnomer to say Selenium2 API since it includes both.
>
> -Luke
>
> >>>http://groups.google.com/group/selenium-users?hl=en.-Hide quoted text -
>
> >> - Show quoted text -
>
> > --
> > 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 athttp://groups.google.com/group/selenium-users?hl=en.- Hide quoted text -

Gulshan Saini

unread,
Sep 8, 2011, 2:26:41 PM9/8/11
to seleniu...@googlegroups.com
in above example driver is

WebDriver driver = new FireFoxDriver();

now  you can do anything with this driver as you did in selenium 1.

driver.get(......);
|
|
|
driver.quit(-----);

Douglas Pennington

unread,
Sep 8, 2011, 3:07:45 PM9/8/11
to Selenium Users
I'm using IE (app only works in IE and FF is not an option), what
would that be. Or a better question is there documentation you can
recommend for this?

Thank you.

Luke Inman-Semerau

unread,
Sep 8, 2011, 6:24:02 PM9/8/11
to seleniu...@googlegroups.com
WebDriver driver = InternetExplorerDriver();

This is the official docs... 

http://seleniumhq.org/docs/03_webdriver.html

but there is more info out there, like also the official wiki:
http://code.google.com/p/selenium/wiki/InternetExplorerDriver

and I'm sure google has some more info too...

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.

Douglas Pennington

unread,
Sep 9, 2011, 2:16:29 PM9/9/11
to Selenium Users
Okay, I'm using WebDriver now.

I've the following:

oDefaultSelenium.clickAt("id=td0",
"1,1"); //This clicks on the menu called "Desktop"
oDefaultSelenium.selectFrame("id=BHOpen"); //iframe
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

ArrayList<WebElement> ls=new ArrayList<WebElement>();
WebDriver driver = new HtmlUnitDriver();
ls = (ArrayList<WebElement>)
driver.findElements(By.className("XPmenu"));
System.out.print(ls.size());

My arraylist is alway 0. I'm still trying to get at the menu items
under the Desktop menu. At this point, I'm completely stumped. I'm
able to click on that menu if I use the ID of that element, but not
anything else.

Help!

Luke Inman-Semerau

unread,
Sep 9, 2011, 2:32:43 PM9/9/11
to seleniu...@googlegroups.com
Ummm.... because you are instantiating a new HtmlUnitDriver, of course it will return an empty list.

How is oDefaultSelenium constructed? Using WebDriverBackedSelenium?  If so, change the line with HtmlUnitDriver to:

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

If not and you are using just Selenium, you'll have to continue using the RC api and not webdriver.

Douglas Pennington

unread,
Sep 9, 2011, 2:38:56 PM9/9/11
to Selenium Users
I'm defining oDefaultSelenium as:

DefaultSelenium oDefaultSelenium = new DefaultSelenium(sServerHost,
iServerPort, sBrowserType, sBaseUrl);
> > > >http://groups.google.com/group/selenium-users?hl=en.-Hide quoted text

Luke Inman-Semerau

unread,
Sep 9, 2011, 2:45:39 PM9/9/11
to seleniu...@googlegroups.com
Two options... drop the webdriver code and only use RC 
or start using webdriverbackedselenium and change that line to be:

DefaultSelenium selenium = new WebDriverBackedSelenium(new InternetExplorerDriver(), sBaseUrl);

and then you can use the line mentioned in my previous email.

Douglas Pennington

unread,
Sep 9, 2011, 3:59:13 PM9/9/11
to Selenium Users
So, if I go back to using RC, how do I work around my issue mentioned
at the begining of this thread?

The thing is, If I do something like:

oDefaultSelenium.clickAt("id=td0", "1,1");

I'm able to click on a menu item.

However, XPATH does not work.
Selecting the iframe before using the XPATH also does not work.
Returns "element not found."


Also, please excuse my Selenium ignorance. I'm a definite newbie to
the Selenium world, and I appreciate the feedback and help I'm getting
here.

Luke Inman-Semerau

unread,
Sep 9, 2011, 4:28:36 PM9/9/11
to seleniu...@googlegroups.com
I'm not certain with the problem you're seeing with RC... I'm no expert there. Any chance you can switch to start using WebDriver?

Douglas Pennington

unread,
Sep 12, 2011, 9:07:58 AM9/12/11
to Selenium Users
I'm up for trying anything to solve this problem.

Do I need to do anything special with my current code to switch from
using RC to WebDriver?

Luke Inman-Semerau

unread,
Sep 12, 2011, 4:27:47 PM9/12/11
to seleniu...@googlegroups.com
You only need to change the constructor on the DefaultSelenium object (like I wrote in a previous email here) and then you'll be able to use WebDriver and keep the old selenium RC code.

Douglas Pennington

unread,
Sep 13, 2011, 2:21:40 PM9/13/11
to Selenium Users
Do I need to change the selenium RC jar I'm using or have linked in my
Eclipse?

Luke Inman-Semerau

unread,
Sep 13, 2011, 2:28:15 PM9/13/11
to seleniu...@googlegroups.com
I guess I assumed you had everything linked in already from a 2.X version... which contains both RC and WebDriver. Since 2.6.0 was just released today, go ahead and remove your current one and download the latest :) 


You can either grab the zip (Java Client Drivers) or just the Standalone-Server jar and link it in. (The zip contains other jars that are dependencies that you may need).

Douglas Pennington

unread,
Sep 16, 2011, 10:24:17 AM9/16/11
to Selenium Users
Thanks everyone. I got the WebDriver to work with my application. So
far I can only interact with the elements using XPATH, which is fine
for the moment
and gets the automation effort on its way.

Thanks again!

On Sep 13, 2:21 pm, Douglas Pennington <dapennington1...@gmail.com>
wrote:
> Do I need to change the selenium RC jar I'm using or have linked in my
> Eclipse?
>
> On Sep 12, 4:27 pm, Luke Inman-Semerau <luke.seme...@gmail.com> wrote:
>
>
>
> > You only need to change the constructor on the DefaultSelenium object (like
> > I wrote in a previous email here) and then you'll be able to use WebDriver
> > and keep the old selenium RC code.
>
> > On Mon, Sep 12, 2011 at 6:07 AM, Douglas Pennington <
>
> > dapennington1...@gmail.com> wrote:
> > > I'm up for trying anything to solve this problem.
>
> > > Do I need to do anything special with my current code to switch from
> > > using RC to WebDriver?
>
> > > On Sep 9, 4:28 pm, Luke Inman-Semerau <luke.seme...@gmail.com> wrote:
> > > > I'm not certain with the problem you're seeing with RC... I'm no expert
> > > > there. Any chance you can switch to start using WebDriver?
>
> > > > On Fri, Sep 9, 2011 at 12:59 PM, Douglas Pennington <
>
> > > > dapennington1...@gmail.com> wrote:
> > > > > So, if I go back to using RC,  how do I work around my issue mentioned
> > > > > at the begining of this thread?
>
> > > > > The thing is,  If I do something like:
>
> > > > > oDefaultSelenium.clickAt("id=td0", "1,1");
>
> > > > > I'm able to click on a menu item.
>
> > > > > However, XPATH does not work.
> > > > > Selecting theiframebefore using the XPATH also does not work.
> > - Show quoted text -- Hide quoted text -
Reply all
Reply to author
Forward
0 new messages