0

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.

closed as off-topic by Michael Durrant, Kevin McKenzie, Nitin Rastogi, Bharat Mane, NarendraC Apr 30 at 12:14

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about software development unrelated to testing are off-topic here, but can be asked on Stack Overflow." – Michael Durrant, Kevin McKenzie, Nitin Rastogi, Bharat Mane, NarendraC
If this question can be reworded to fit the rules in the help center, please edit the question.

3

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.

1

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')]"
webdriver.get($URL_OF_THE_PAGE)
text_element = webdriver.find_element_by_xpath(text_xpath)
# prints whether it has been found or not
if text_element:
    print("Element found")
else:
    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.