Abhishek Yadav
Abhishek Yadav

Reputation: 459

not able to click on following link using selenium webdriver

I am not able to click on following link using selenium webdriver:

<center>
  <a class="xyz" style="" href="/Folder">My Folders</a>
  <span></span>
</center> 

I am using the code:

abhiFX.findElement(By.partialLinkText("My Folders")).click();

Upvotes: 1

Views: 1989

Answers (2)

Bfcm
Bfcm

Reputation: 2746

Try to use xpath instead:

public void clickElement() {

    try {
        WebElement element = abhiFX.findElement(
            By.xpath("//a[contains(text(),'My Folders')]"));
        element.click();
    } catch (InvalidSelectorException e) {
        throw new AssertionError("[FAIL] Click Element: Xpath is invalid.");
    } catch (NoSuchElementException e) {
        throw new AssertionError(
                "[FAIL] Click Element: Unable to locate element");
    }

}

Upvotes: 2

dokaspar
dokaspar

Reputation: 8624

I see these potential problems:

  1. Are you sure that your HTML 'works' at all if you load the page in a browser and click on the link? What's the expected result of the click?
  2. Is your driver abhiFX initialized properly? Does .click() on other elements work well?

Upvotes: 3

Related Questions