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.
-
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.Kate Paulk– Kate Paulk2018年11月14日 13:37:36 +00:00Commented 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.Paul Muir– Paul Muir2018年11月14日 21:20:36 +00:00Commented 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.Rajesh Om– Rajesh Om2018年11月15日 05:18:01 +00:00Commented Nov 15, 2018 at 5:18
1 Answer 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.