0

How to click a link with selenium Webdriver which have same names

driver.findElement(By.linkText("View All")).click();

There are some other Links also having same name like View All

4
  • can you please post the sample HTML code? Commented Aug 25, 2016 at 4:56
  • You mentioned that you have multiple "View All" links ryt? are they present inside any table with different user names? Commented Aug 25, 2016 at 4:58
  • does the two widgets have different class names or any different properties? Please post the HTML code for both the widgets.This will help us to provide you some reliable solutions Commented Aug 25, 2016 at 5:02
  • Let us continue this discussion in chat. Commented Aug 25, 2016 at 5:03

1 Answer 1

2

You should try to locate unique link with combinations of other attribute of this link such as class name and text by using xpath as below :-

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement link = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//a[contains(@class, 'absence-viewall') and contains(text(), 'View All')]")));
link.click();

Or if this link has unique class name, best way to use By.cssSelector() as below :-

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement link = wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("a.absence-viewall")));
link.click();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.