Wednesday, December 29, 2010

Locating Elements with Same name


These are the buttons with same name





Here goes the links with same name

Link

Link


Program to locate this are


package file;

import org.openqa.selenium.server.SeleniumServer;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.SeleneseTestCase;
import com.thoughtworks.selenium.Selenium;

public class Twonames extends SeleneseTestCase {

private SeleniumServer seleniumServer;
private Selenium selenium = new DefaultSelenium( "localhost",4444,
"*chrome",
"http://localhost:8080/same.html");

public void setUp() throws Exception
{
seleniumServer = new SeleniumServer();
seleniumServer.start();
selenium.start();
}

public void SameName() throws Exception {
selenium.open("/same.html");
selenium.setSpeed("2000");
selenium.click("//input[@id='button'and position()=2 ]");
System.out.println("clicked 2nd button");
selenium.click("//input[@id='button'and position()=1 ]");
System.out.println("clicked 1st Button");
selenium.click("//a[@name='search' and position()=2]");
System.out.println("clicked 2nd Link");
selenium.isTextPresent("HI");
}


public void tearDown()throws Exception
{
selenium.stop();
seleniumServer.stop();
}

}


No comments:

Post a Comment