To click()
on the element with text as App Configuration you can use either of the following Locator Strategies:
linkText
:
driver.findElement(By.linkText("App Configuration")).click();
cssSelector
:
driver.findElement(By.cssSelector("a[href='/docs/configuration']")).click();
xpath
:
driver.findElement(By.xpath("//a[@href='/docs/configuration' and text()='App Configuration']")).click();
Ideally, to click()
on the element you need to induce WebDriverWait for the elementToBeClickable()
and you can use either of the following Locator Strategies:
linkText
:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.linkText("App Configuration"))).click();
cssSelector
:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a[href='/docs/configuration']"))).click();
xpath
:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@href='/docs/configuration' and text()='App Configuration']"))).click();
You can find a couple of relevant detailed discussions in: