I am working on Patient registration module , found thousand of patient ids,I need to verify particular ID/text are available or not in the search registration page. how can i validate the search Registration webtable.

2 Answers 2


You want to iterate over the rows of the table and verify if the text you are looking for is present. Once you locate the 'table' element you can do something like this in Java:

public boolean isRegistered(String patientID) {
    for(WebElement row : table.findElements(By.tagName("tr"))) {
        if(row.getText().contains(patientID)) {
            return true;
    return false;

or using Java 8 and lambda expressions:

public boolean isRegistered(String patientID) {
    return table.findElements(By.tagName("tr")).stream().anyMatch(row -> row.getText().contains(patientID));

For any other languages the situation is the same - locate the table, iterate over the rows and check if any of them contains the patient data you are looking for.


If all you need to do is check whether a particular string is on a page (in any element/field, as if you would use the "find" function in browser), you can do it in Selenium with Python using XPath for locating the element:

# locating the element
text_xpath = "//*[contains(text(), '$THE_STRING_YOU_ARE_LOOKING_FOR')]"
text_element = webdriver.find_element_by_xpath(text_xpath)
# prints whether it has been found or not
if text_element:
    print("Element found")
    print("Element not found")

Mind you this is a bit slow, as it will go through the whole DOM looking for the string. You can speed it up by only searching particular element/section of the DOM.

Not the answer you're looking for? Browse other questions tagged or ask your own question.