Search⌘ K

Text Assertions

Explore how to assert text in web elements like labels, spans, and divs using Selenium WebDriver in Node.js. This lesson helps you understand various assertion techniques to verify page content accurately, enhancing your web application testing skills.

Assert label text

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

HTML
<label id="receipt_number">NB123454</label>

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

Javascript (babel-node)
driver.findElement(By.id("label_1")).getText().then(function(the_elem_text) {
assert.equal("First Label", the_elem_text);
});
...