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

How to write a prg for selenium.click(//a[3]/img); in java

on Mon Aug 03, 2009 2:23 pm
Hi,

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

Thank for u r good support.

Yours

Lahari.
avatar
Advisor
------------------------
------------------------
Posts : 383
Join date : 2009-07-30
Location : India
http://seleniumforum.forumotion.net

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 ();
obj.setUp();
}

public void setUp() throws InterruptedException
{
browser = new DefaultSelenium("localhost",4444,"*iexplore","http://google.com");
browser.start();
browser.open("http://google.com");
browser.windowMaximize();
browser.type("q", "selenium");
browser.click("btnG");
browser.waitForPageToLoad("30000");

}


}


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
Lahari
Posts : 5
Join date : 2009-08-03

Re: How to write a prg for selenium.click(//a[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
{

setUp("http://1.0.0.2/","*chrome");
public void testNew() throws Exception
{

selenium.open("/sample/checkUserSession.do?method=checkUserSession&status=active&msg=");

selenium.type("userId","admin");
selenium.type("password","1234");
selenium.click("mybutton");
selenium.waitForPageToLoad("30000");
selenium.click("//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 selenium.click("//a[3]/img"); line.


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

avatar
Advisor
------------------------
------------------------
Posts : 383
Join date : 2009-07-30
Location : India
http://seleniumforum.forumotion.net

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

on Wed Aug 12, 2009 11:45 am
hi,

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

Bye
Lahari
Posts : 5
Join date : 2009-08-03

Thx its working

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

Re: How to write a prg for selenium.click(//a[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,
senthilm
lasombra
Posts : 1
Join date : 2009-11-26

Re: How to write a prg for selenium.click(//a[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:
selenium.isElementPresent(elem
whereas elem = "//div[@id='menuTree1']/img[1]"
But when I want to click on that element
selenium.click(elem)
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:

selenium.selectFrame(frame);
selenium.selectFrame("index=1");


Thanks for your help, lasombra
Sponsored content

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

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