0

I have one table in which there is one column called "state". I have to find and click on link which matches with text "closed successful" in that column. xpath for each cell in that column is

 "//*[@id='TicketID_xxxxxx']/td[7]/div

Where xxxxxx are numbers of tickets. So how can I find matching text with different xpath values and click on it using selenium webdriver. Please help.

(Optional- I have to click on that element, click on back and find next element with same matching text)

7
  • Please add some HTML so that people can help you with that. What language binding are you using with Selenium ? Commented Apr 4, 2016 at 9:46
  • Which part of HTML should i add, and i am using java with selenium Commented Apr 4, 2016 at 9:50
  • Some example of the table you're trying to process, a few rows. Commented Apr 4, 2016 at 9:53
  • It is 7th row, and column called state with different values like "new", "open", "closed successful". i have to match text "closed successful" and click on it. i have mentioned xpath of column cells. Commented Apr 4, 2016 at 10:10
  • why do you write td[7] but say about 7th row? Commented Apr 4, 2016 at 10:13

3 Answers 3

4

Hi Sanket Patel please do it like below

driver.get(yourWebPageLInk); // link to your web-table web page

    // take all of the element under Column "State" inside list

    List<WebElement> columVal =  driver.findElements(By.xpath("//*[starts-with(@id,'TicketID_')]/td[7]/div"));
    // count the size of the list to match with the size of the column state
    System.out.println("Size of the contents in the column state is : " +columVal.size());

    // now for matching one of the content and then performing some action please
    // start a for loop

    String oneVal = "closed successful";
    for(int i=0;i<columVal.size();i++){
        System.out.println("Content text is : " + columVal.get(i).getText());
        // match the content here in the if loop
        if(columVal.get(i).getText().equals(oneVal)){
            // perform action
            columVal.get(i).click();
        }
    }
Sign up to request clarification or add additional context in comments.

1 Comment

i am glad it helped you please mark it as your answer
0

You can use the text() method

String text = "someText";
driver.findElement(By.xpath("//div[contains(text(), '" + text + "')]")).click();

Or with cssSelector

String text = "someText";
driver.findElement(By.cssSelector("div:contains('" + text + "')")).click();

Comments

0

You can use the TableDriver extension to Selenium WebDriver for situations like this. (https://github.com/jkindwall/TableDriver.Java). It would be helpful if there was more detailed info about the table in question, however if we assume that the table has a column "link" containing the link you need to click, and we assume the id of the main table element is "tabelId" you could do it like this:

Table table = Table.create(driver.findElement(By.id("tableId"));
WebElement element = table.findCell("state=closed successful", "link").Element;
element.findElement(By.tagName("a")).Click();

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.