leysmi
leysmi

Reputation: 23

Clicking on a link in a table

I have a table of four columns. The data in the first column is a name of a group in which I can click on to go to a new page to modify the group data.

I can get the text of that group name, but I am unable to click on it. I'm trying to go through each row and get the status of each group (located in column 4). If it's on hold, I want to modify the data of that group.

Here is my code: Why will it not click on the group name?

List<WebElement> elems = driver.findElements(By.xpath("//table[@id='nameOfTable']/tbody/tr"));
for (WebElement rowElem : elems)
{
    List<WebElement> cells = rowElem.findElements(By.xpath("td"));

    if(cells.get(3).getText().equalsIgnoreCase("Hold"))
    {
        System.out.println(cells.get(0).getText()); //
        cells.get(0).click; // This will not click on the link
    }
}

Upvotes: 2

Views: 9217

Answers (2)

Anders
Anders

Reputation: 15397

You would need to say cells.get(0).click();.

I believe you are missing a couple of parentheses...

Upvotes: 2

Assiance
Assiance

Reputation: 56

It is because you are clicking the whole cell, not the link inside the cell. Try:

cells.get(0).findElements(By.TagName("a")).Click();

If the link is an <a> tag it will work, but you can use id, classname, etc... if it isn't.

Upvotes: 3

Related Questions