Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8591169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:27:54+00:00 2026-06-11T23:27:54+00:00

I have two methods which does the same. Unfortunately, Option Two works some times

  • 0

I have two methods which does the same. Unfortunately, Option Two works some times (5 out of 10 times)… Option One works rarely (2 out of 10 times)… Is there a better to way to write this code…

One:

public static void clickOnLinkinWebTable(WebElement webTable, String lookUpValue) throws MyException {
    for (WebElement row : webTable.findElements(By.xpath("tr"))) {
        for (WebElement col : row.findElements(By.xpath("td")))
            if (col.getText().equals(lookUpValue)) {
                col.findElement(By.partialLinkText(lookUpValue)).click();
                return;
            }

    }
}

Two:

public static void clickOnLinkinWebTable(String tableXpathRow, String lookUpValue) throws MyException {
    int row_cnt = driver.findElements(By.xpath(tableXpathRow)).size();
        for (int row_num = 1; row_num <= row_cnt; row_num++) {
                int col_cnt = driver.findElements(By.xpath(tableXpathRow+"["+row_num+"]"+"/td")).size();
                for (int col_num = 1; col_num <= col_cnt; col_num++) {
                String cellValue = driver.findElement(By.xpath(tableXpathRow+"["+row_num+"]/td["+col_num+"]")).getText();
                if(lookUpValue.equalsIgnoreCase(cellValue)){
                    WebElement elementLink = driver.findElement(By.xpath(tableXpathRow+"["+row_num+"]/td["+col_num+ "]/a"));
                elementLink.click();
                return;
            }
        }
    }
}

Works some times / rarely: I am running tests in a test suite. This method is called atleast 15 times in the test suite (in the same page). Works some times but does n’t work sometime when this method is called.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:27:55+00:00Added an answer on June 11, 2026 at 11:27 pm

    Can use xpath of the lookup for clicking on the webtable link.

    driver.findElement(By.xpath(path)).click();
    

    where

    path="//td[contains(text(),lookupvalue)]"
    

    (this can be done by string concat like below)

    String s="//td[contains(text(), ";
    String qt=")]";
    String path=(s.concat(lookupvalue)).concat(qt);
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two methods, one called straight after another, which both throw the exact
I have two files called file_utils.h and file_utils.cpp which contain some methods and variables
I have two helper methods inside a custom View which are called by their
I have found only two methods (SaveFile, LoadFile) which save in a file. How
I have two methods, one that I use to convert an image to a
I have a select box, which i can populate using two methods. First -
As often happens, I have a nice solution to one problem, which unfortunately causes
I have two action methods that are called using the same action name, however,
For example, I have a class that has two strings, one of which must
I have a method which compares two objects and returns a list of all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.