html
php
css
c
python
mysql
database
xcode
multithreading
eclipse
json
perl
facebook
oracle
cocoa
tsql
delphi
jsp
dom
Keeping in mind your excerpt from the question:
I need to verify the values xyz, abcd, 1234, 5678 on the webpage
I suggest you try to identify these values using locators and then asserting/verifying the same.
In this example I have used XPath ( a bit verbose for clarity)as the locating strategy.Hope this helps.
try { assertEquals("xyz", driver.findElement(By.xpath("//table//tr[1]/td[1]")).getText()); } catch (Error e) { verificationErrors.append(e.toString()); } try { assertEquals("abcd", driver.findElement(By.xpath("//table//tr[1]/td[2]")).getText()); } catch (Error e) { verificationErrors.append(e.toString()); } try { assertEquals("1234", driver.findElement(By.xpath("//table//tr[2]/td[1]")).getText()); } catch (Error e) { verificationErrors.append(e.toString()); } try { assertEquals("5678", driver.findElement(By.xpath("//table//tr[2]/td[2]")).getText()); } catch (Error e) { verificationErrors.append(e.toString()); }
Your approach will depend on whether that table will only ever contain 2 rows and 2 columns. Will the rows and columns always exist in the same order? If not then the xcode example provider before will work, if not you might need to be a bit more creative.
One approach that I've used before to crawl through a table is similar to this.
Define a WebElement that represents your table.
WebElement yourTable = driver.findElement(By.tagname("table"));
Next create a List of WebElements that represent each row in the table.
List<WebElement> tableRows = yourTable.findElements(By.tagname("tr");
Finally, you can loop through the rows of the table until you find the data you are looking for.
for(int i=0; i<tableRows.size(); i++){ WebElement row = tableRows.get(i); now do whatever you want with your WebElement that represents a single row of the table; }
Hope this helps.