I am trying to click on a link which is in a list. As can be seen from the screenshot I am trying to click on the "Algeria" link. How can I get there?
capture of list and elements
The Css is as follows - #\33 \2c ALG
xpath is - //*[@id="3,ALG"]
I have tried finding it by xpath and cssSelector but with no luck
By.linkText() locator fits here perfectly:
driver.findElement(By.linkText("Algeria")).click();
You might also need to add an Explicit Wait to wait for element to be present:
WebDriverWait wait = new WebDriverWait(webDriver, 10);
WebElement link = wait.until(ExpectedConditions.presenceOfElementLocated(By.linkText("Algeria")));
link.click();
You may also need to open up the list before clicking the link:
WebDriverWait wait = new WebDriverWait(webDriver, 10);
WebElement linkList = wait.until(ExpectedConditions.presenceOfElementLocated(By.className("oList")));
linkList.click();
WebElement link = wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Algeria")));
link.click();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With