Playwright + Java · Lesson 3 of 38
Module 3: Strings
Your task
Implement cleanAndExtractId:
Write it in the editor, then press Check answer (Ctrl + Enter).
equals() & equalsIgnoreCase(): Always use .equals() instead of == for String content comparisons.contains(): Validating that a banner contains an expected keyword.trim(): Removing leading and trailing whitespace from UI text.split(): Extracting dynamic values like order confirmation numbers.String bannerText = " Order #98432 placed successfully! ";
String cleaned = bannerText.trim();
boolean hasOrder = cleaned.startsWith("Order #");
String orderId = cleaned.split("#")[1].split(" ")[0]; // "98432"Every web page contains text: headers, order IDs, confirmation toasts, and table cells. In this lesson, you will master Java String methods like equals, contains, trim, and split to reliably parse and assert UI texts. Let's begin!
Part of the Playwright + Java course (Playwright with Java). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
== compares memory addresses (object references), not characters. Web pages create new String objects in memory, so always use str1.equals(str2).
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___