user3765899 user3765899 - 4 months ago 8x
Java Question

Selenium cannot find item list input

Hello I'm learning selenium and I've met first problem. I was searching for it very long and tested a lot of solutions and none of them worked for me.

This is how looks button which I want to click (I want to click Events button in navbar)

<div id="navbar-items" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="#about">About</a></li>
<li><a href="#events">Events</a></li>
<li><a href="#venues">Venues</a></li>
<li><a href="#bookings">Bookings</a></li>
<li><a href="#monitor">Monitor</a></li>
<li><a href="admin">Administration</a></li>

And here is my java code:

public class SeleniumTest {

public void startWebDriver() throws InterruptedException{

WebDriver driver = new FirefoxDriver();

Assert.assertTrue("title should start differently",
driver.getTitle().startsWith("Ticket Monster"));




// I also was trying this and nothing clicked events button
//driver.findElement(By.xpath("(//span[@class='nav navbar-nav'])2]")).click();
//driver.findElement(By.cssSelector("ul > li:nth-child(2)")).click();

Here is website on which on I am practising it may be helpful.

I will be very thankful for every help.


Try the below code and let me know.

WebDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, 10);

And Xpath is the slowest, so xpath is used when we don't have any option. Fortunately the xpath is taking the id so here it is all good.