I can't find this element using selenium java webdriver.

I have a before class method that loads the firefox driver and set the WebDriverWait. Then I have a test method to look for the elements with the code below.

It never finds the following element. Can someone help me in figuring out this issue?

//Click More Genres 
<li class="moreGenres">
<span>More Genres</span>

The code:

Actions builder = new Actions(driver);  
WebElement moregenres = driver.findElement(By.cssSelector(".moreGenres>span"));

or using:

//Click More Genres
WebElement moregenres = driver.findElement(By.cssSelector(".moreGenres>span"));

//Click More Genres
WebElement moregenres = driver.findElement(By.xpath("//li[@class='moreGenres']"));


//Click More Genres
WebElement moregenres = driver.findElement(By.xpath("//li[@class='moreGenres']/span"));

2 Answers 2


Try using


as an xpath

For css, what you have -


does work -

enter image description here

so see if maybe you have that li in more than one place perhaps?

or maybe make it a bit more specific such as




or (better)


It might also be better to have style rules for the li's rather than thru adding spans perhaps.

  • 1
    Thanks. You are right. It ended up being two instances of the element. So I had to use another tag before it plus this part of the element to differentiate between the two elements. So that each instance of the element has its own unique xpath or cssSelector. However, now I have a new problem. My eclipse testng doesn't run the save code changes, it keeps remembering the previously bad runs with the failing code despite I'm making new code changes. Do you know how I can solve this? Jan 6, 2016 at 6:32
  • Sorry, I don't use eclipse. Maybe post that as a separate question? Jan 6, 2016 at 11:32
  • Thanks. The reason it wasn't taking the new code, was actually I still had some old xpaths that I didn't update to the new xpath in the bottom of the page code. That was why it was still running an old xpath. Now it's solved. Thanks for helping me figure out that it was two instances of the same element. That helped a lot. Jan 6, 2016 at 16:17

U can try this below code, hope it helps u :

xpath("//li[contains(@class, 'moreGenres')]")
  • 2
    Could you add more information, please? We prefer answers to be more than just a one liner with a code snippet.
    – Kate Paulk
    Jan 6, 2016 at 17:25
  • Can you replace U with you so it is written in proper English?
    – dzieciou
    Jan 8, 2016 at 6:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.