I am trying to automate a web application using Selenium WebDriver
with Java
I want to click on "Create Tournaments"
link. I used xpath
for identifying that element. But I'm getting the error
org.openqa.selenium.NoSuchElementException: no such element:
Unable to locate element: {"method":"xpath","selector":"//*[@id='createtournaments_li']/a"}
Can anybody help me in this..?
Code:
package User;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import junit.framework.Assert;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class QZO_Create_Tournament {
WebDriver driver;
private Properties properties;
private final String PROPERTY_FILE_NAME = "constant.properties";
public QZO_Create_Tournament() {
properties = new Properties();
try {
InputStream inputStream = getClass().getClassLoader().getResourceAsStream(PROPERTY_FILE_NAME);
if(null != inputStream)
{
properties.load(inputStream);
}
} catch (IOException e) {
e.printStackTrace();
}
}
@BeforeTest
public void openBrowser()
{
System.setProperty("webdriver.chrome.driver", "D:\\MyProjects\\SeleniumTrials\\chromedriver_win32\\chromedriver.exe");
driver= new ChromeDriver();
driver.get(properties.getProperty("VAR_ADMIN_URL"));
driver.manage().window().maximize();
}
@Test
public void login() throws BiffException, IOException, InterruptedException{
WebElement username=driver.findElement(By.xpath(properties.getProperty("VAR_ADMIN_USERNAME")));
username.clear();
username.sendKeys("admin");
Thread.sleep(1000);
WebElement password=driver.findElement(By.xpath(properties.getProperty("VAR_ADMIN_PASSWORD")));
password.sendKeys("123456");
Thread.sleep(1000);
WebElement continuebutton=driver.findElement(By.xpath(properties.getProperty("VAR_ADMIN_CONTINUE")));
continuebutton.click();
Thread.sleep(20000);
}
@Test
public void createtournament(){
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
WebElement createtournament=driver.findElement(By.xpath(properties.getProperty("VAR_CREATETOURNAMENT")));
// WebElement createtournament = driver.findElement(By.xpath("//a[@href='/Admin/CreateEditTournaments']"));
createtournament.click();
Select tournamenttype = new Select(driver.findElement(By.xpath(properties.getProperty("VAR_TOURNAMENTTYPE"))));
tournamenttype.selectByVisibleText("Planned Tournament");}}
Properties file :
VAR_ADMIN_USERNAME = //*[@id='username_txt']
VAR_ADMIN_PASSWORD = //*[@id='password_txt']
VAR_ADMIN_CONTINUE = //*[@id='main-section']/div/div/section[2]/div[2]/a/span
VAR_CREATETOURNAMENT = //*[@id='createtournaments_li']/a
VAR_TOURNAMENTTYPE = //*[@id='main-section']/div/div/div[2]/div[2]/ul/li/div/div/select