How to verify the Literal text on the UI
-
20-06-2021 - |
質問
Here is part of the UI where i have got some literal texts like
Opportunity Name Momentum Test (ID=AANA-19KVBE)
Account Account Internal
Owner Christopher Braden
Sales Order Region North America
Locale English United States
Currency US Dollar
The piece of code for the above is as follows
<table class="datatable" width="100%">
<tbody>
<tr class="oddrow">
<td>Opportunity Name</td>
<td class="wrap_content">
Momentum Test (ID=AANA-19KVBE)
<br>
<a target="_blank" href="http://www.example.com">View in Salesforce</a>
</td>
</tr>
<tr class="evenrow">
<td>Account</td>
<td class="wrap_content">
Akamai Internal
<br>
<a target="_blank" href="http://www.example.com">View in Salesforce</a>
</td>
</tr>
<tr class="oddrow">
<td>Owner</td>
<td>Christopher Braden</td>
</tr>
<tr class="evenrow">
<td>Sales Order Region</td>
<td>North America</td>
</tr>
<tr class="oddrow">
<td>Locale</td>
<td>English - United States</td>
</tr>
<tr class="evenrow">
<td>Currency</td>
<td>US Dollar</td>
</tr>
</tbody>
I need to retrieve these values individually, store it to compare it in a different page.
for example : i need to know "United States" is stored under "Location"
Please help me
Thanks & Regards Kiran
解決
You can read and store all this information in a Map -
Map<String,String> map = new Map<String,String>;
List<WebElement> list = driver.findElements(By.xpath("//*[@class='datatable']/tbody/tr"));
for(int i=1;i<=list.size();i++){
String key = driver.findElement(By.xpath("//*[@class='datatable']/tbody/tr["+i+"]/td[1]")).getText();
String value = driver.findElement(By.xpath("//*[@class='datatable']/tbody/tr["+i+"]/td[2]")).getText();
map.put(key,value);
}
In this way you can read all the information in the table and store it in Map to be used later. Let me know if this works for you.
所属していません StackOverflow