How to get a cell selected by a specific column value in selenium












1















I need to select the cell with order id #1968 for a dynamic table.



I have printed the table using code below , Please suggest how I can get the specific cell with value #1968 selected ?






	WebElement Table_element =commonFunctions.driver.findElement(By.xpath("//*[@id='active']/div/table"));
//To locate rows of table.
List < WebElement > rows_table = Table_element.findElements(By.tagName("tr"));
//To calculate no of rows In table.
int rows_count = rows_table.size();
//Loop will execute till the last row of table.
for (int row = 0; row < rows_count; row++) {
//To locate columns(cells) of that specific row.
List < WebElement > Columns_row = rows_table.get(row).findElements(By.tagName("td"));
//To calculate no of columns (cells). In that specific row.
int columns_count = Columns_row.size();
System.out.println("Number of cells In Row " + row + " are " + columns_count);
//Loop will execute till the last cell of that specific row.
for (int column = 0; column < columns_count; column++) {
// To retrieve text from that specific cell.
celtext = Columns_row.get(column).getText();
System.out.println("Cell Value of row number " + row + " and column number " + column + " Is " + celtext);


}
}






Result of table : Number of cells In Row 1 are 4 Cell Value of row
number 1 and column number 0 Is #1975 Cell Value of row number 1 and
column number 1 Is SERVICE1535721248947 FOR $156 - Edited service Name
Cell Value of row number 1 and column number 2 Is Delivered Cell Value
of row number 1 and column number 3 Is Nov 5 Number of cells In Row 2
are 4 Cell Value of row number 2 and column number 0 Is #1971 Cell
Value of row number 2 and column number 1 Is service1538918641775 Cell
Value of row number 2 and column number 2 Is Delivered Cell Value of
row number 2 and column number 3 Is Oct 18 Number of cells In Row 3
are 4 Cell Value of row number 3 and column number 0 Is #1969 Cell
Value of row number 3 and column number 1 Is service1538918641775 Cell
Value of row number 3 and column number 2 Is Delivered Cell Value of
row number 3 and column number 3 Is Oct 18 Number of cells In Row 4
are 4 Cell Value of row number 4 and column number 0 Is #1968 Cell
Value of row number 4 and column number 1 Is service1538918641775 Cell
Value of row number 4 and column number 2 Is Delivered Cell Value of
row number 4 and column number 3 Is Oct 18




HTML Of the table :






  <table class="table table-bordered table-hover">
<thead>
<tr>
<th>Order#</th>
<th>Title</th>
<th>Status</th>
<th>Created</th>
</tr>
</thead>
<tbody>
<tr class="entry">
<td class="gig first">
<div><a href="#">
#1983
</a>
</td>
<td><a href="#">SERVICE1535721248947 FOR $156 - Edited service Name</a></td>
<td class="status delivered" ><span class="label mt1 order-label-delivered">Delivered</span></td>
<td class="datetime last"><div>Nov 11</div></td>
</tr>
<tr class="entry">
<td class="gig first">
<div><a href="#">
#1982
</a>
</td>
<td><a href="#">SERVICE1535721248947 FOR $156 - Edited service Name</a></td>
<td class="status delivered"><span class="label mt1 order-label-delivered">Delivered</span></td>
<td class="datetime last"><div>Nov 11</div></td>
</tr>

</tbody>
</table>












share|improve this question




















  • 1





    Have you tried find element by xpath //td[contains(text(), '#1968')]?

    – KunLun
    Nov 8 '18 at 15:00













  • Hi @raul1ro , I get error using the above: Unable to locate element: {"method":"xpath","selector":"//td[contains(text(), '#1983')]"} However, #1983 is there in first row first column itself

    – Ritika Arora
    Nov 12 '18 at 10:12













  • Can you get us some sample of html with your table table ?

    – KunLun
    Nov 12 '18 at 12:20











  • Hi @raul1ro , I have edited the question and added the code of table , Thanks

    – Ritika Arora
    Nov 13 '18 at 13:53











  • I have now used xpath("//td/div/a[contains(text(), OrderId)]" , I think it should work .

    – Ritika Arora
    Nov 13 '18 at 14:05
















1















I need to select the cell with order id #1968 for a dynamic table.



I have printed the table using code below , Please suggest how I can get the specific cell with value #1968 selected ?






	WebElement Table_element =commonFunctions.driver.findElement(By.xpath("//*[@id='active']/div/table"));
//To locate rows of table.
List < WebElement > rows_table = Table_element.findElements(By.tagName("tr"));
//To calculate no of rows In table.
int rows_count = rows_table.size();
//Loop will execute till the last row of table.
for (int row = 0; row < rows_count; row++) {
//To locate columns(cells) of that specific row.
List < WebElement > Columns_row = rows_table.get(row).findElements(By.tagName("td"));
//To calculate no of columns (cells). In that specific row.
int columns_count = Columns_row.size();
System.out.println("Number of cells In Row " + row + " are " + columns_count);
//Loop will execute till the last cell of that specific row.
for (int column = 0; column < columns_count; column++) {
// To retrieve text from that specific cell.
celtext = Columns_row.get(column).getText();
System.out.println("Cell Value of row number " + row + " and column number " + column + " Is " + celtext);


}
}






Result of table : Number of cells In Row 1 are 4 Cell Value of row
number 1 and column number 0 Is #1975 Cell Value of row number 1 and
column number 1 Is SERVICE1535721248947 FOR $156 - Edited service Name
Cell Value of row number 1 and column number 2 Is Delivered Cell Value
of row number 1 and column number 3 Is Nov 5 Number of cells In Row 2
are 4 Cell Value of row number 2 and column number 0 Is #1971 Cell
Value of row number 2 and column number 1 Is service1538918641775 Cell
Value of row number 2 and column number 2 Is Delivered Cell Value of
row number 2 and column number 3 Is Oct 18 Number of cells In Row 3
are 4 Cell Value of row number 3 and column number 0 Is #1969 Cell
Value of row number 3 and column number 1 Is service1538918641775 Cell
Value of row number 3 and column number 2 Is Delivered Cell Value of
row number 3 and column number 3 Is Oct 18 Number of cells In Row 4
are 4 Cell Value of row number 4 and column number 0 Is #1968 Cell
Value of row number 4 and column number 1 Is service1538918641775 Cell
Value of row number 4 and column number 2 Is Delivered Cell Value of
row number 4 and column number 3 Is Oct 18




HTML Of the table :






  <table class="table table-bordered table-hover">
<thead>
<tr>
<th>Order#</th>
<th>Title</th>
<th>Status</th>
<th>Created</th>
</tr>
</thead>
<tbody>
<tr class="entry">
<td class="gig first">
<div><a href="#">
#1983
</a>
</td>
<td><a href="#">SERVICE1535721248947 FOR $156 - Edited service Name</a></td>
<td class="status delivered" ><span class="label mt1 order-label-delivered">Delivered</span></td>
<td class="datetime last"><div>Nov 11</div></td>
</tr>
<tr class="entry">
<td class="gig first">
<div><a href="#">
#1982
</a>
</td>
<td><a href="#">SERVICE1535721248947 FOR $156 - Edited service Name</a></td>
<td class="status delivered"><span class="label mt1 order-label-delivered">Delivered</span></td>
<td class="datetime last"><div>Nov 11</div></td>
</tr>

</tbody>
</table>












share|improve this question




















  • 1





    Have you tried find element by xpath //td[contains(text(), '#1968')]?

    – KunLun
    Nov 8 '18 at 15:00













  • Hi @raul1ro , I get error using the above: Unable to locate element: {"method":"xpath","selector":"//td[contains(text(), '#1983')]"} However, #1983 is there in first row first column itself

    – Ritika Arora
    Nov 12 '18 at 10:12













  • Can you get us some sample of html with your table table ?

    – KunLun
    Nov 12 '18 at 12:20











  • Hi @raul1ro , I have edited the question and added the code of table , Thanks

    – Ritika Arora
    Nov 13 '18 at 13:53











  • I have now used xpath("//td/div/a[contains(text(), OrderId)]" , I think it should work .

    – Ritika Arora
    Nov 13 '18 at 14:05














1












1








1








I need to select the cell with order id #1968 for a dynamic table.



I have printed the table using code below , Please suggest how I can get the specific cell with value #1968 selected ?






	WebElement Table_element =commonFunctions.driver.findElement(By.xpath("//*[@id='active']/div/table"));
//To locate rows of table.
List < WebElement > rows_table = Table_element.findElements(By.tagName("tr"));
//To calculate no of rows In table.
int rows_count = rows_table.size();
//Loop will execute till the last row of table.
for (int row = 0; row < rows_count; row++) {
//To locate columns(cells) of that specific row.
List < WebElement > Columns_row = rows_table.get(row).findElements(By.tagName("td"));
//To calculate no of columns (cells). In that specific row.
int columns_count = Columns_row.size();
System.out.println("Number of cells In Row " + row + " are " + columns_count);
//Loop will execute till the last cell of that specific row.
for (int column = 0; column < columns_count; column++) {
// To retrieve text from that specific cell.
celtext = Columns_row.get(column).getText();
System.out.println("Cell Value of row number " + row + " and column number " + column + " Is " + celtext);


}
}






Result of table : Number of cells In Row 1 are 4 Cell Value of row
number 1 and column number 0 Is #1975 Cell Value of row number 1 and
column number 1 Is SERVICE1535721248947 FOR $156 - Edited service Name
Cell Value of row number 1 and column number 2 Is Delivered Cell Value
of row number 1 and column number 3 Is Nov 5 Number of cells In Row 2
are 4 Cell Value of row number 2 and column number 0 Is #1971 Cell
Value of row number 2 and column number 1 Is service1538918641775 Cell
Value of row number 2 and column number 2 Is Delivered Cell Value of
row number 2 and column number 3 Is Oct 18 Number of cells In Row 3
are 4 Cell Value of row number 3 and column number 0 Is #1969 Cell
Value of row number 3 and column number 1 Is service1538918641775 Cell
Value of row number 3 and column number 2 Is Delivered Cell Value of
row number 3 and column number 3 Is Oct 18 Number of cells In Row 4
are 4 Cell Value of row number 4 and column number 0 Is #1968 Cell
Value of row number 4 and column number 1 Is service1538918641775 Cell
Value of row number 4 and column number 2 Is Delivered Cell Value of
row number 4 and column number 3 Is Oct 18




HTML Of the table :






  <table class="table table-bordered table-hover">
<thead>
<tr>
<th>Order#</th>
<th>Title</th>
<th>Status</th>
<th>Created</th>
</tr>
</thead>
<tbody>
<tr class="entry">
<td class="gig first">
<div><a href="#">
#1983
</a>
</td>
<td><a href="#">SERVICE1535721248947 FOR $156 - Edited service Name</a></td>
<td class="status delivered" ><span class="label mt1 order-label-delivered">Delivered</span></td>
<td class="datetime last"><div>Nov 11</div></td>
</tr>
<tr class="entry">
<td class="gig first">
<div><a href="#">
#1982
</a>
</td>
<td><a href="#">SERVICE1535721248947 FOR $156 - Edited service Name</a></td>
<td class="status delivered"><span class="label mt1 order-label-delivered">Delivered</span></td>
<td class="datetime last"><div>Nov 11</div></td>
</tr>

</tbody>
</table>












share|improve this question
















I need to select the cell with order id #1968 for a dynamic table.



I have printed the table using code below , Please suggest how I can get the specific cell with value #1968 selected ?






	WebElement Table_element =commonFunctions.driver.findElement(By.xpath("//*[@id='active']/div/table"));
//To locate rows of table.
List < WebElement > rows_table = Table_element.findElements(By.tagName("tr"));
//To calculate no of rows In table.
int rows_count = rows_table.size();
//Loop will execute till the last row of table.
for (int row = 0; row < rows_count; row++) {
//To locate columns(cells) of that specific row.
List < WebElement > Columns_row = rows_table.get(row).findElements(By.tagName("td"));
//To calculate no of columns (cells). In that specific row.
int columns_count = Columns_row.size();
System.out.println("Number of cells In Row " + row + " are " + columns_count);
//Loop will execute till the last cell of that specific row.
for (int column = 0; column < columns_count; column++) {
// To retrieve text from that specific cell.
celtext = Columns_row.get(column).getText();
System.out.println("Cell Value of row number " + row + " and column number " + column + " Is " + celtext);


}
}






Result of table : Number of cells In Row 1 are 4 Cell Value of row
number 1 and column number 0 Is #1975 Cell Value of row number 1 and
column number 1 Is SERVICE1535721248947 FOR $156 - Edited service Name
Cell Value of row number 1 and column number 2 Is Delivered Cell Value
of row number 1 and column number 3 Is Nov 5 Number of cells In Row 2
are 4 Cell Value of row number 2 and column number 0 Is #1971 Cell
Value of row number 2 and column number 1 Is service1538918641775 Cell
Value of row number 2 and column number 2 Is Delivered Cell Value of
row number 2 and column number 3 Is Oct 18 Number of cells In Row 3
are 4 Cell Value of row number 3 and column number 0 Is #1969 Cell
Value of row number 3 and column number 1 Is service1538918641775 Cell
Value of row number 3 and column number 2 Is Delivered Cell Value of
row number 3 and column number 3 Is Oct 18 Number of cells In Row 4
are 4 Cell Value of row number 4 and column number 0 Is #1968 Cell
Value of row number 4 and column number 1 Is service1538918641775 Cell
Value of row number 4 and column number 2 Is Delivered Cell Value of
row number 4 and column number 3 Is Oct 18




HTML Of the table :






  <table class="table table-bordered table-hover">
<thead>
<tr>
<th>Order#</th>
<th>Title</th>
<th>Status</th>
<th>Created</th>
</tr>
</thead>
<tbody>
<tr class="entry">
<td class="gig first">
<div><a href="#">
#1983
</a>
</td>
<td><a href="#">SERVICE1535721248947 FOR $156 - Edited service Name</a></td>
<td class="status delivered" ><span class="label mt1 order-label-delivered">Delivered</span></td>
<td class="datetime last"><div>Nov 11</div></td>
</tr>
<tr class="entry">
<td class="gig first">
<div><a href="#">
#1982
</a>
</td>
<td><a href="#">SERVICE1535721248947 FOR $156 - Edited service Name</a></td>
<td class="status delivered"><span class="label mt1 order-label-delivered">Delivered</span></td>
<td class="datetime last"><div>Nov 11</div></td>
</tr>

</tbody>
</table>








	WebElement Table_element =commonFunctions.driver.findElement(By.xpath("//*[@id='active']/div/table"));
//To locate rows of table.
List < WebElement > rows_table = Table_element.findElements(By.tagName("tr"));
//To calculate no of rows In table.
int rows_count = rows_table.size();
//Loop will execute till the last row of table.
for (int row = 0; row < rows_count; row++) {
//To locate columns(cells) of that specific row.
List < WebElement > Columns_row = rows_table.get(row).findElements(By.tagName("td"));
//To calculate no of columns (cells). In that specific row.
int columns_count = Columns_row.size();
System.out.println("Number of cells In Row " + row + " are " + columns_count);
//Loop will execute till the last cell of that specific row.
for (int column = 0; column < columns_count; column++) {
// To retrieve text from that specific cell.
celtext = Columns_row.get(column).getText();
System.out.println("Cell Value of row number " + row + " and column number " + column + " Is " + celtext);


}
}





	WebElement Table_element =commonFunctions.driver.findElement(By.xpath("//*[@id='active']/div/table"));
//To locate rows of table.
List < WebElement > rows_table = Table_element.findElements(By.tagName("tr"));
//To calculate no of rows In table.
int rows_count = rows_table.size();
//Loop will execute till the last row of table.
for (int row = 0; row < rows_count; row++) {
//To locate columns(cells) of that specific row.
List < WebElement > Columns_row = rows_table.get(row).findElements(By.tagName("td"));
//To calculate no of columns (cells). In that specific row.
int columns_count = Columns_row.size();
System.out.println("Number of cells In Row " + row + " are " + columns_count);
//Loop will execute till the last cell of that specific row.
for (int column = 0; column < columns_count; column++) {
// To retrieve text from that specific cell.
celtext = Columns_row.get(column).getText();
System.out.println("Cell Value of row number " + row + " and column number " + column + " Is " + celtext);


}
}





  <table class="table table-bordered table-hover">
<thead>
<tr>
<th>Order#</th>
<th>Title</th>
<th>Status</th>
<th>Created</th>
</tr>
</thead>
<tbody>
<tr class="entry">
<td class="gig first">
<div><a href="#">
#1983
</a>
</td>
<td><a href="#">SERVICE1535721248947 FOR $156 - Edited service Name</a></td>
<td class="status delivered" ><span class="label mt1 order-label-delivered">Delivered</span></td>
<td class="datetime last"><div>Nov 11</div></td>
</tr>
<tr class="entry">
<td class="gig first">
<div><a href="#">
#1982
</a>
</td>
<td><a href="#">SERVICE1535721248947 FOR $156 - Edited service Name</a></td>
<td class="status delivered"><span class="label mt1 order-label-delivered">Delivered</span></td>
<td class="datetime last"><div>Nov 11</div></td>
</tr>

</tbody>
</table>





  <table class="table table-bordered table-hover">
<thead>
<tr>
<th>Order#</th>
<th>Title</th>
<th>Status</th>
<th>Created</th>
</tr>
</thead>
<tbody>
<tr class="entry">
<td class="gig first">
<div><a href="#">
#1983
</a>
</td>
<td><a href="#">SERVICE1535721248947 FOR $156 - Edited service Name</a></td>
<td class="status delivered" ><span class="label mt1 order-label-delivered">Delivered</span></td>
<td class="datetime last"><div>Nov 11</div></td>
</tr>
<tr class="entry">
<td class="gig first">
<div><a href="#">
#1982
</a>
</td>
<td><a href="#">SERVICE1535721248947 FOR $156 - Edited service Name</a></td>
<td class="status delivered"><span class="label mt1 order-label-delivered">Delivered</span></td>
<td class="datetime last"><div>Nov 11</div></td>
</tr>

</tbody>
</table>






java selenium-webdriver






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 13:51







Ritika Arora

















asked Nov 8 '18 at 14:53









Ritika AroraRitika Arora

155




155








  • 1





    Have you tried find element by xpath //td[contains(text(), '#1968')]?

    – KunLun
    Nov 8 '18 at 15:00













  • Hi @raul1ro , I get error using the above: Unable to locate element: {"method":"xpath","selector":"//td[contains(text(), '#1983')]"} However, #1983 is there in first row first column itself

    – Ritika Arora
    Nov 12 '18 at 10:12













  • Can you get us some sample of html with your table table ?

    – KunLun
    Nov 12 '18 at 12:20











  • Hi @raul1ro , I have edited the question and added the code of table , Thanks

    – Ritika Arora
    Nov 13 '18 at 13:53











  • I have now used xpath("//td/div/a[contains(text(), OrderId)]" , I think it should work .

    – Ritika Arora
    Nov 13 '18 at 14:05














  • 1





    Have you tried find element by xpath //td[contains(text(), '#1968')]?

    – KunLun
    Nov 8 '18 at 15:00













  • Hi @raul1ro , I get error using the above: Unable to locate element: {"method":"xpath","selector":"//td[contains(text(), '#1983')]"} However, #1983 is there in first row first column itself

    – Ritika Arora
    Nov 12 '18 at 10:12













  • Can you get us some sample of html with your table table ?

    – KunLun
    Nov 12 '18 at 12:20











  • Hi @raul1ro , I have edited the question and added the code of table , Thanks

    – Ritika Arora
    Nov 13 '18 at 13:53











  • I have now used xpath("//td/div/a[contains(text(), OrderId)]" , I think it should work .

    – Ritika Arora
    Nov 13 '18 at 14:05








1




1





Have you tried find element by xpath //td[contains(text(), '#1968')]?

– KunLun
Nov 8 '18 at 15:00







Have you tried find element by xpath //td[contains(text(), '#1968')]?

– KunLun
Nov 8 '18 at 15:00















Hi @raul1ro , I get error using the above: Unable to locate element: {"method":"xpath","selector":"//td[contains(text(), '#1983')]"} However, #1983 is there in first row first column itself

– Ritika Arora
Nov 12 '18 at 10:12







Hi @raul1ro , I get error using the above: Unable to locate element: {"method":"xpath","selector":"//td[contains(text(), '#1983')]"} However, #1983 is there in first row first column itself

– Ritika Arora
Nov 12 '18 at 10:12















Can you get us some sample of html with your table table ?

– KunLun
Nov 12 '18 at 12:20





Can you get us some sample of html with your table table ?

– KunLun
Nov 12 '18 at 12:20













Hi @raul1ro , I have edited the question and added the code of table , Thanks

– Ritika Arora
Nov 13 '18 at 13:53





Hi @raul1ro , I have edited the question and added the code of table , Thanks

– Ritika Arora
Nov 13 '18 at 13:53













I have now used xpath("//td/div/a[contains(text(), OrderId)]" , I think it should work .

– Ritika Arora
Nov 13 '18 at 14:05





I have now used xpath("//td/div/a[contains(text(), OrderId)]" , I think it should work .

– Ritika Arora
Nov 13 '18 at 14:05












2 Answers
2






active

oldest

votes


















0














I don't know if I understand this correctly, but you want to iterate through the tables Order Id's and find a specific one.



How I would do it is:



List<WebElement> orders = this.getDriver().findElements(By.xpath("/html/body/table/tbody/tr/td[1]/div/a"));


That code will retrieve all the elements inside of the first column and add it into the orders list.



After doing that you can have an integer index variable that will track the row number of the specific element, if it exists.



int index = 0; 

for(WebElement elements: orders){
index++;
if(elements.text.equals("#1968"){
//Here you can click on the link or do whatever...
this.getDriver().findElement(By.xpath("/html/body/table/tbody/tr[index]/td[1]/div/a")).click();
}

}


I cant remember the exact syntax for selenium but I know I iterated through a list of elements and clicked on a specific one according to my data set.






share|improve this answer
























  • Please note that sometimes selenium driver returns an error for not finding an element, use WebDriverWait wait = new WebDriverWait(this.getDriver(), 30) to expand the duration, another helpful thing to use is the Action class, so here is the better solution: Action act = new Action(this.getDriver()); act.click(wait.until(ExpectedConditions.elementToBeClickable(By.id("someid"))).build().perform();

    – Mini-Man
    Nov 26 '18 at 8:51





















0














In my current project I have application, where are many tables. I usually defining separate columns as



List<WebElement> nameColumnList, List<WebElement> statusColumnList



Then I am iterating for Name column, searching for row number, which has name, which I need. Then, using this number, I am getting text from Status column and verifying it's value. This how I am getting all values from table and clicking or validating them.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53210229%2fhow-to-get-a-cell-selected-by-a-specific-column-value-in-selenium%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I don't know if I understand this correctly, but you want to iterate through the tables Order Id's and find a specific one.



    How I would do it is:



    List<WebElement> orders = this.getDriver().findElements(By.xpath("/html/body/table/tbody/tr/td[1]/div/a"));


    That code will retrieve all the elements inside of the first column and add it into the orders list.



    After doing that you can have an integer index variable that will track the row number of the specific element, if it exists.



    int index = 0; 

    for(WebElement elements: orders){
    index++;
    if(elements.text.equals("#1968"){
    //Here you can click on the link or do whatever...
    this.getDriver().findElement(By.xpath("/html/body/table/tbody/tr[index]/td[1]/div/a")).click();
    }

    }


    I cant remember the exact syntax for selenium but I know I iterated through a list of elements and clicked on a specific one according to my data set.






    share|improve this answer
























    • Please note that sometimes selenium driver returns an error for not finding an element, use WebDriverWait wait = new WebDriverWait(this.getDriver(), 30) to expand the duration, another helpful thing to use is the Action class, so here is the better solution: Action act = new Action(this.getDriver()); act.click(wait.until(ExpectedConditions.elementToBeClickable(By.id("someid"))).build().perform();

      – Mini-Man
      Nov 26 '18 at 8:51


















    0














    I don't know if I understand this correctly, but you want to iterate through the tables Order Id's and find a specific one.



    How I would do it is:



    List<WebElement> orders = this.getDriver().findElements(By.xpath("/html/body/table/tbody/tr/td[1]/div/a"));


    That code will retrieve all the elements inside of the first column and add it into the orders list.



    After doing that you can have an integer index variable that will track the row number of the specific element, if it exists.



    int index = 0; 

    for(WebElement elements: orders){
    index++;
    if(elements.text.equals("#1968"){
    //Here you can click on the link or do whatever...
    this.getDriver().findElement(By.xpath("/html/body/table/tbody/tr[index]/td[1]/div/a")).click();
    }

    }


    I cant remember the exact syntax for selenium but I know I iterated through a list of elements and clicked on a specific one according to my data set.






    share|improve this answer
























    • Please note that sometimes selenium driver returns an error for not finding an element, use WebDriverWait wait = new WebDriverWait(this.getDriver(), 30) to expand the duration, another helpful thing to use is the Action class, so here is the better solution: Action act = new Action(this.getDriver()); act.click(wait.until(ExpectedConditions.elementToBeClickable(By.id("someid"))).build().perform();

      – Mini-Man
      Nov 26 '18 at 8:51
















    0












    0








    0







    I don't know if I understand this correctly, but you want to iterate through the tables Order Id's and find a specific one.



    How I would do it is:



    List<WebElement> orders = this.getDriver().findElements(By.xpath("/html/body/table/tbody/tr/td[1]/div/a"));


    That code will retrieve all the elements inside of the first column and add it into the orders list.



    After doing that you can have an integer index variable that will track the row number of the specific element, if it exists.



    int index = 0; 

    for(WebElement elements: orders){
    index++;
    if(elements.text.equals("#1968"){
    //Here you can click on the link or do whatever...
    this.getDriver().findElement(By.xpath("/html/body/table/tbody/tr[index]/td[1]/div/a")).click();
    }

    }


    I cant remember the exact syntax for selenium but I know I iterated through a list of elements and clicked on a specific one according to my data set.






    share|improve this answer













    I don't know if I understand this correctly, but you want to iterate through the tables Order Id's and find a specific one.



    How I would do it is:



    List<WebElement> orders = this.getDriver().findElements(By.xpath("/html/body/table/tbody/tr/td[1]/div/a"));


    That code will retrieve all the elements inside of the first column and add it into the orders list.



    After doing that you can have an integer index variable that will track the row number of the specific element, if it exists.



    int index = 0; 

    for(WebElement elements: orders){
    index++;
    if(elements.text.equals("#1968"){
    //Here you can click on the link or do whatever...
    this.getDriver().findElement(By.xpath("/html/body/table/tbody/tr[index]/td[1]/div/a")).click();
    }

    }


    I cant remember the exact syntax for selenium but I know I iterated through a list of elements and clicked on a specific one according to my data set.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 13 '18 at 14:30









    Mini-ManMini-Man

    163




    163













    • Please note that sometimes selenium driver returns an error for not finding an element, use WebDriverWait wait = new WebDriverWait(this.getDriver(), 30) to expand the duration, another helpful thing to use is the Action class, so here is the better solution: Action act = new Action(this.getDriver()); act.click(wait.until(ExpectedConditions.elementToBeClickable(By.id("someid"))).build().perform();

      – Mini-Man
      Nov 26 '18 at 8:51





















    • Please note that sometimes selenium driver returns an error for not finding an element, use WebDriverWait wait = new WebDriverWait(this.getDriver(), 30) to expand the duration, another helpful thing to use is the Action class, so here is the better solution: Action act = new Action(this.getDriver()); act.click(wait.until(ExpectedConditions.elementToBeClickable(By.id("someid"))).build().perform();

      – Mini-Man
      Nov 26 '18 at 8:51



















    Please note that sometimes selenium driver returns an error for not finding an element, use WebDriverWait wait = new WebDriverWait(this.getDriver(), 30) to expand the duration, another helpful thing to use is the Action class, so here is the better solution: Action act = new Action(this.getDriver()); act.click(wait.until(ExpectedConditions.elementToBeClickable(By.id("someid"))).build().perform();

    – Mini-Man
    Nov 26 '18 at 8:51







    Please note that sometimes selenium driver returns an error for not finding an element, use WebDriverWait wait = new WebDriverWait(this.getDriver(), 30) to expand the duration, another helpful thing to use is the Action class, so here is the better solution: Action act = new Action(this.getDriver()); act.click(wait.until(ExpectedConditions.elementToBeClickable(By.id("someid"))).build().perform();

    – Mini-Man
    Nov 26 '18 at 8:51















    0














    In my current project I have application, where are many tables. I usually defining separate columns as



    List<WebElement> nameColumnList, List<WebElement> statusColumnList



    Then I am iterating for Name column, searching for row number, which has name, which I need. Then, using this number, I am getting text from Status column and verifying it's value. This how I am getting all values from table and clicking or validating them.






    share|improve this answer




























      0














      In my current project I have application, where are many tables. I usually defining separate columns as



      List<WebElement> nameColumnList, List<WebElement> statusColumnList



      Then I am iterating for Name column, searching for row number, which has name, which I need. Then, using this number, I am getting text from Status column and verifying it's value. This how I am getting all values from table and clicking or validating them.






      share|improve this answer


























        0












        0








        0







        In my current project I have application, where are many tables. I usually defining separate columns as



        List<WebElement> nameColumnList, List<WebElement> statusColumnList



        Then I am iterating for Name column, searching for row number, which has name, which I need. Then, using this number, I am getting text from Status column and verifying it's value. This how I am getting all values from table and clicking or validating them.






        share|improve this answer













        In my current project I have application, where are many tables. I usually defining separate columns as



        List<WebElement> nameColumnList, List<WebElement> statusColumnList



        Then I am iterating for Name column, searching for row number, which has name, which I need. Then, using this number, I am getting text from Status column and verifying it's value. This how I am getting all values from table and clicking or validating them.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 8 '18 at 17:59









        UkrainisUkrainis

        1809




        1809






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53210229%2fhow-to-get-a-cell-selected-by-a-specific-column-value-in-selenium%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Full-time equivalent

            さくらももこ

            13 indicted, 8 arrested in Calif. drug cartel investigation