Go down
Posts : 5
Join date : 2009-08-03

How to write a prg for[3]/img); in java

on Mon Aug 03, 2009 2:23 pm

Gr8 to see everyone...
In Selenium RC
How to write a prg for[3]/img); in java.

Thank for u r good support.


Posts : 383
Join date : 2009-07-30
Location : India

A sample java code as per requirement.

on Tue Aug 04, 2009 10:52 am
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.SeleneseTestCase;
import com.thoughtworks.selenium.Selenium;

public class Sample extends SeleneseTestCase
public Selenium browser;

public static void main(String arg[]) throws InterruptedException
Sample obj = new Sample ();

public void setUp() throws InterruptedException
browser = new DefaultSelenium("localhost",4444,"*iexplore","");
browser.type("q", "selenium");"btnG");



NOTE: For running this code you have to link you project or program to a selenium and Junit jar. After linking the jar to the editor. You can compile it and run it. This code will open a google site, enter selenium and click on search button. Finally result will display. I used eclipse for coding in java and link all jar file to the project.

As per your question , if you want to click on a link which u provide in question. Just change the URL name of your application and use the click command given in above code.

I hope this will help you. Very Happy cheers
Posts : 5
Join date : 2009-08-03

Re: How to write a prg for[3]/img); in java

on Tue Aug 11, 2009 7:20 pm
Hi Admin,
Thank u so much for u r help.
I am unable to execute ur code in Junit code.
Find the below details u can understand where i am getting problem.
On executing the application in Selenium IDE generated the below script.

public class NewTest extends SeleneseTestCase

public void setUp() throws Exception

public void testNew() throws Exception

selenium.waitForPageToLoad("30000");"//a[3]/img");-> (This code is generated for Logout operation)
assertTrue(selenium.getConfirmation().matches ("^Do you want to LogOut [\\s\\S]$"));

In Selenium RC executing the same script.I am getting error “
Element id not found” in this"//a[3]/img"); line.

From front end Logout is a button.But it is a Image.
how to run"//a[3]/img") in Selenium RC.
Plz help me

Posts : 383
Join date : 2009-07-30
Location : India

Re: How to write a prg for[3]/img); in java

on Wed Aug 12, 2009 11:45 am

There may be many reasons for this like:

1. waitforpageload command is not waiting till time specified and control moves further when page is still loading. Try to debug code line by line and see.

2. The locator is not exactly same appear on screen. try to use xpath or dom locator. May be that id generated on run time and change every time.

3. before click command place verifyElementPresent command to debug.

Try all this and let me know. I hope this will help u

Posts : 5
Join date : 2009-08-03

Thx its working

on Wed Aug 12, 2009 6:33 pm
Very Happy its working
Active particpant
Active particpant
Posts : 19
Join date : 2009-09-15

Re: How to write a prg for[3]/img); in java

on Tue Sep 15, 2009 6:41 pm
Lahari wrote:Thx.
its working

Hi I am facing the same problem. can u tell me how did u solve the problem?

Thanks & Regards,
Posts : 1
Join date : 2009-11-26

Re: How to write a prg for[3]/img); in java

on Thu Nov 26, 2009 6:44 pm
Hi all
I try to click an element (an img within a div tag). I first check if the element I am looking for is present, which returns true:
whereas elem = "//div[@id='menuTree1']/img[1]"
But when I want to click on that element
An exception is raised:
com.thoughtworks.selenium.SeleniumException: ERROR: Element //div[@id='menuTree1']/img[1] not found
The element I want to access is within a frame, within an iframe, which I select before:


Thanks for your help, lasombra
Sponsored content

Re: How to write a prg for[3]/img); in java

Back to top
Permissions in this forum:
You cannot reply to topics in this forum