2

Using selenium Webdriver+Java- I am looking for a way to identify and or verify a value in a table. There are more columns in the table, but I am only concerned with the Country column, Also the number of rows varies as well as the location of the value I am looking for.

So, say, I am looking for Country there. the country = "Germany", who could exist in any row 1 to 9 or 10 or 20 etc.How could I locate and verify that user exist with Database query?

**Company** **Contact** **Country**
Alfreds Futterkiste Maria Anders Germany
Centro comercial Moctezuma Francisco Chang Mexico
Ernst Handel Roland Mendel Austria
Island Trading Helen Bennett UK
Laughing Bacchus Winecellars Yoshi Tannamuri Canada
Magazzini Alimentari Riuniti Giovanni Rovelli Italy

HTML Table Code:

<table>
 <tr>
 <th>Company</th>
 <th>Contact</th>
 <th>Country</th>
 </tr>
 <tr>
 <td>Alfreds Futterkiste</td>
 <td>Maria Anders</td>
 <td>Germany</td>
 </tr>
 <tr>
 <td>Centro comercial Moctezuma</td>
 <td>Francisco Chang</td>
 <td>Mexico</td>
 </tr>
 <tr>
 <td>Ernst Handel</td>
 <td>Roland Mendel</td>
 <td>Austria</td>
 </tr>
 <tr>
 <td>Island Trading</td>
 <td>Helen Bennett</td>
 <td>UK</td>
 </tr>
 <tr>
 <td>Laughing Bacchus Winecellars</td>
 <td>Yoshi Tannamuri</td>
 <td>Canada</td>
 </tr>
 <tr>
 <td>Magazzini Alimentari Riuniti</td>
 <td>Giovanni Rovelli</td>
 <td>Italy</td>
 </tr>
</table>

I need to get the country name from ui and verify that country name is exist in database using java code.

João Farias
11.2k2 gold badges21 silver badges41 bronze badges
asked Nov 14, 2018 at 11:57
3
  • Do you need to check that the country value is in the database, or do you need to check that the country value is in the data that's displayed on the page? The answer to your question will be different if you need to check the database than if you need to find the data on the page. Commented Nov 14, 2018 at 13:37
  • Yeah I think they are confusing database table and HTML table. If you're looking for database than you don't need selenium at all. Commented Nov 14, 2018 at 21:20
  • I need to get the country name from ui and verify that country name is exist in database using java code. Commented Nov 15, 2018 at 5:18

1 Answer 1

1

(on mobile, sorry for formatting)

String country = "Germany"
// All ui rows
List<WebElements> rows = driver.findElements('tr');
// Is there any row with Country?
Boolean existOnUI = !rows.stream().filter(
 row => row.findElement('td:nth-of-type(3)')
 .getText().equals(country))
 .isEmpty();
//If so, is there some row with Country on the DB?
Boolean existOnDB = !dbDriver.execute("Select * from Table where country =" + country + ";").isEmpty();

The variables existOnDB and existOnUI hold information if the country exists.

answered Nov 15, 2018 at 9:34
2
  • I will try and tell you Commented Nov 15, 2018 at 11:55
  • Can you please make code properly,not able to understand Commented Nov 15, 2018 at 12:58

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.