So I'm working on this project and I need to find the correct locator for Selenium testing. I've tried a bunch of different combinations and I can't find the right one to click this link. Everything I try throws a No Such Element exception.
I need to click the first link in the unordered list. Here is the HTML
<main id="content" role="main">
<nav id="product-list" role="navigation">
<ul>
<li id="firstTile">
<a class="productLink" href="***LINK***" target="_top">
<img src="***image ref***">
<p>
<span class="productName" title="First Tile"></span>
<br>
<small>This is the text for the first tile</small>
</p>
</a>
<div class="item-footer cf">
<hr>
</li>
<li id="secondTile">
<li id="thirdTile">
<li id="fourthTile" class="coming-soon">
</ul>
</nav>
<div class="extra-links cf">
</main>
Here is my Java:
Test class
// All imports
public class Test {
private Home home;
//All other variables
@Before
public void setup() {
driver = new FirefoxDriver();
}
@Test
public void clickFirstTile() {
home = new Home(driver);
home.clickFirstTile();
}
@After
public void tearDown() {
driver.quit();
}
}
And also my Home Page Object class:
public class Home {
private WebDriver driver;
By firstTileBtnLocator = By.id("firstTile");
public Home(WebDriver driver) {
this.driver = driver;
// I've replaced my site with this fake url. The real site url works.
driver.navigate().to("http://myfakesite.com");
}
public void clickFirstTile() {
driver.findElement(firstTileBtnLocator).click();
}
}