- Lahari
- Posts : 5
Join date : 2009-08-03
How to write a prg for selenium.click(//a[3]/img); in java
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.
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.
A sample java code as per requirement.
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.
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.
- Lahari
- Posts : 5
Join date : 2009-08-03
Re: How to write a prg for selenium.click(//a[3]/img); in java
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
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
Re: How to write a prg for selenium.click(//a[3]/img); in java
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
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
- senthilm.aynaraActive particpant
- Posts : 19
Join date : 2009-09-15
Re: How to write a prg for selenium.click(//a[3]/img); in java
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
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
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
- How to write in FCK editor in selenium RC by using java code.
- Select the “back” button of the Firefox browser to right click and Select the Option from the right click Menu in Selenium Web Driver - Java
- How to write selenium java code for doubleClick on a record using webdriver
- [Help] Problem of running selenium Testcase[Java Junit] with Selenium RC
- i had already written a java web driver, but, I would like to write a new php page using that java source code
Permissions in this forum:
You cannot reply to topics in this forum