Text Assertions

Learn how to assert text using Selenium and try it out yourself.

Assert label text

Label tags are commonly used in web pages to wrap some text like:

Press + to interact
<label id="receipt_number">NB123454</label>

It is very useful to assert such texts from time to time. We can do so by:

Press + to interact
driver.findElement(By.id("label_1")).getText().then(function(the_elem_text) {
assert.equal("First Label", the_elem_text);
});
...