0
0
Selenium Javatesting~15 mins

Page title and URL retrieval in Selenium Java - Deep Dive

Choose your learning style9 modes available
Overview - Page title and URL retrieval
What is it?
Page title and URL retrieval means getting the current web page's title and its web address (URL) using automated tests. In Selenium with Java, this helps verify that the browser is showing the right page during testing. The title is the text shown on the browser tab, and the URL is the exact address in the browser's address bar. These are basic but important checks in web testing.
Why it matters
Without checking the page title and URL, tests might miss if the browser navigated to the wrong page or if the page loaded incorrectly. This can cause bugs to go unnoticed, leading to bad user experiences or broken features. Retrieving and verifying these values ensures the website behaves as expected and helps catch navigation errors early.
Where it fits
Before learning this, you should know how to set up Selenium WebDriver and open a web page. After this, you can learn more about interacting with page elements, waiting for page loads, and validating page content. This topic is a foundation for verifying navigation and page correctness in automated tests.
Mental Model
Core Idea
Retrieving the page title and URL is like reading the label and address on a package to confirm it’s the right one before opening it.
Think of it like...
Imagine you order a book online. When the delivery arrives, you check the label (page title) and the address (URL) on the package to make sure it’s the book you ordered and it came to your house. Similarly, in testing, you check the page title and URL to confirm the browser shows the correct page.
┌─────────────────────────────┐
│        Browser Window       │
│ ┌───────────────────────┐ │
│ │ Page Title (Tab Text) │ │
│ └───────────────────────┘ │
│ ┌───────────────────────┐ │
│ │ URL (Address Bar)     │ │
│ └───────────────────────┘ │
│ ┌───────────────────────┐ │
│ │ Web Page Content      │ │
│ └───────────────────────┘ │
└─────────────────────────────┘
Build-Up - 7 Steps
1
FoundationUnderstanding Page Title and URL
🤔
Concept: Learn what page title and URL mean in a web browser context.
The page title is the text shown on the browser tab. It usually describes the page content. The URL is the web address shown in the browser's address bar. Both help identify the page you are viewing.
Result
You can recognize the page title and URL visually in any browser.
Knowing what the page title and URL represent helps you understand why verifying them matters in testing.
2
FoundationSetting Up Selenium WebDriver
🤔
Concept: Prepare the Selenium WebDriver to open a browser and load a web page.
Install Selenium Java bindings and a browser driver (like ChromeDriver). Write code to create a WebDriver instance and open a URL using driver.get("https://example.com").
Result
A browser window opens and loads the specified web page.
Setting up WebDriver is essential before you can retrieve page title or URL.
3
IntermediateRetrieving Page Title in Selenium Java
🤔Before reading on: do you think driver.getTitle() returns the page title as a String or an object? Commit to your answer.
Concept: Use the getTitle() method of WebDriver to get the current page title as a String.
Example: String title = driver.getTitle(); System.out.println("Page title is: " + title);
Result
The console prints the exact title text of the current page.
Understanding that getTitle() returns a simple String lets you easily compare it with expected titles in tests.
4
IntermediateRetrieving Current URL in Selenium Java
🤔Before reading on: do you think driver.getCurrentUrl() returns the URL before or after any redirects? Commit to your answer.
Concept: Use the getCurrentUrl() method of WebDriver to get the current page URL as a String after all navigation and redirects.
Example: String url = driver.getCurrentUrl(); System.out.println("Current URL is: " + url);
Result
The console prints the full URL of the page currently loaded in the browser.
Knowing getCurrentUrl() reflects the final URL after redirects helps you verify navigation correctness.
5
IntermediateUsing Assertions to Verify Title and URL
🤔Before reading on: do you think assertions stop the test immediately on failure or continue running? Commit to your answer.
Concept: Use assertions to check if the retrieved title and URL match expected values, causing test failure if they don't.
Example with JUnit: import static org.junit.jupiter.api.Assertions.*; String expectedTitle = "Example Domain"; assertEquals(expectedTitle, driver.getTitle()); String expectedUrl = "https://example.com/"; assertEquals(expectedUrl, driver.getCurrentUrl());
Result
Test passes if title and URL match; fails with error if not.
Assertions provide automated checks that confirm the page is correct, preventing silent errors.
6
AdvancedHandling Dynamic Titles and URLs
🤔Before reading on: do you think exact string matching always works for titles and URLs on dynamic sites? Commit to your answer.
Concept: Learn strategies to handle pages where titles or URLs change dynamically, like using contains() or regex matching.
Example: String title = driver.getTitle(); assertTrue(title.contains("Welcome")); String url = driver.getCurrentUrl(); assertTrue(url.matches("https://example.com/page/\d+"));
Result
Tests pass if title or URL partially match expected patterns, allowing flexibility.
Knowing how to handle dynamic values prevents flaky tests that fail due to small expected changes.
7
ExpertAvoiding Common Pitfalls in Title and URL Checks
🤔Before reading on: do you think checking title and URL alone guarantees the page loaded fully and correctly? Commit to your answer.
Concept: Understand the limitations of title and URL checks and learn to combine them with other validations like element presence or page state.
Example: // Title and URL check assertEquals("Home", driver.getTitle()); assertEquals("https://example.com/home", driver.getCurrentUrl()); // Additional check assertTrue(driver.findElement(By.id("main-content")).isDisplayed());
Result
Tests become more reliable by verifying page content along with title and URL.
Knowing that title and URL are necessary but not sufficient checks helps build robust tests.
Under the Hood
When Selenium WebDriver calls getTitle() or getCurrentUrl(), it communicates with the browser through the WebDriver protocol. The browser returns the current page's title or URL from its internal state. These values reflect the page loaded in the active tab, updated after navigation or redirects. The driver does not parse the page itself but relies on the browser's rendering engine to provide accurate information.
Why designed this way?
This design separates test code from browser internals, allowing WebDriver to work with many browsers uniformly. Returning simple strings for title and URL keeps the API easy to use and efficient. Alternatives like parsing page source would be slower and more complex. The WebDriver protocol standardizes these commands for cross-browser compatibility.
┌───────────────┐       ┌───────────────┐       ┌───────────────┐
│ Selenium Test │──────▶│ WebDriver API │──────▶│   Browser     │
│   (Java)      │       │ (Commands)    │       │ (Rendering)   │
└───────────────┘       └───────────────┘       └───────────────┘
        │                      │                      │
        │ getTitle()           │                      │
        │--------------------▶│                      │
        │                      │ get title string     │
        │                      │--------------------▶│
        │                      │                      │
        │                      │◀--------------------│
        │◀---------------------│                      │
        │  returns title string │                      │
Myth Busters - 4 Common Misconceptions
Quick: Does driver.getTitle() always return the page title immediately after driver.get()? Commit yes or no.
Common Belief:driver.getTitle() instantly returns the correct page title right after calling driver.get(url).
Tap to reveal reality
Reality:If the page is still loading or redirecting, getTitle() may return an old or empty title. You often need to wait for the page to load fully before retrieving the title.
Why it matters:Without waiting, tests may fail or pass incorrectly, causing flaky or unreliable results.
Quick: Does driver.getCurrentUrl() return the URL you initially requested or the final URL after redirects? Commit your answer.
Common Belief:driver.getCurrentUrl() always returns the URL passed to driver.get(), ignoring redirects.
Tap to reveal reality
Reality:driver.getCurrentUrl() returns the actual URL loaded in the browser after all redirects and navigation.
Why it matters:Tests that expect the original URL may fail if redirects occur, leading to false negatives.
Quick: Is checking only the page title enough to confirm the page loaded correctly? Commit yes or no.
Common Belief:If the page title is correct, the page has loaded fully and correctly.
Tap to reveal reality
Reality:The title can be correct even if page content is missing or broken. Additional checks are needed for full validation.
Why it matters:Relying solely on title can miss critical page errors, causing bugs to slip through.
Quick: Does getTitle() return the visible text on the page or the title tag content? Commit your answer.
Common Belief:getTitle() returns any visible text on the page.
Tap to reveal reality
Reality:getTitle() returns only the content of the tag in the HTML head, not visible page text.</span></div><div class="dlm-myth-why"><span class="dlm-myth-label"><span class="new-material-symbols icon-hw-20"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="#10B981"><path d="M459-60q-10-3.33-19-10L186.67-260q-12.34-9-19.5-23.33-7.17-14.34-7.17-30v-500q0-27 19.83-46.84Q199.67-880 226.67-880h506.66q27 0 46.84 19.83Q800-840.33 800-813.33v500q0 15.66-7.17 30-7.16 14.33-19.5 23.33L520-70q-9 6.67-19 10t-21 3.33q-11 0-21-3.33Zm-21.67-394-70.66-70.67q-10-10-23.34-9.83-13.33.17-23.33 9.83-10 10-10.17 23.5-.16 13.5 9.84 23.5l95 94.34q10 10 23.33 10 13.33 0 23.33-10l179.34-179.34q10-10 9.5-23.33-.5-13.33-10.17-23.33-10-10-23.5-10.17-13.5-.17-23.5 9.83L437.33-454Z"></path></svg></span>Why it matters:</span><span>Confusing these can lead to wrong assertions and test failures.</span></div></div></div></div></div></article><article class="content-card dlm-card"><div class="code-articles-card-header"><span class="card-icon intro"><span class="new-material-symbols icon-hw-24"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="#3B82F6"><path d="M853.33-315.33V-562l-342 185q-15.33 8.67-32 8.33-16.66-.33-32-9L93.33-571q-9-5.33-12.83-12.67Q76.67-591 76.67-600q0-9 3.83-16.33 3.83-7.34 12.83-12.67l354-193.33q7.67-4.34 15.5-6.5 7.84-2.17 16.5-2.17 8.67 0 16.5 2.17 7.84 2.16 15.5 6.5l391 212.66q8.67 4.34 13.17 12.5Q920-589 920-580v264.67q0 14.33-9.5 23.83-9.5 9.5-23.83 9.5-14.34 0-23.84-9.5t-9.5-23.83Zm-406 177.66-220-120q-16-9-25.33-24.66-9.33-15.67-9.33-34.34v-166.66l254.66 139q15.34 8.66 32 8.66 16.67 0 32-8.66l254.67-139v166.66q0 18.67-9.33 34.34-9.34 15.66-25.34 24.66l-220 120q-7.66 4.34-15.5 6.5Q488-129 479.33-129q-8.66 0-16.5-2.17-7.83-2.16-15.5-6.5Z"></path></svg></span></span><span class="codefly-card-title">Expert Zone</span></div><div class="code-articles-card-body"><div class="dlm-expert-nuances"><div class="dlm-nuance-item"><div class="dlm-nuance-number">1</div><div class="dlm-nuance-text">Some websites dynamically change the page title after loading using JavaScript, so getTitle() may change during the test session.</div></div><div class="dlm-nuance-item"><div class="dlm-nuance-number">2</div><div class="dlm-nuance-text">In multi-tab or multi-window tests, getTitle() and getCurrentUrl() always refer to the active window; switching windows is necessary to get info from others.</div></div><div class="dlm-nuance-item"><div class="dlm-nuance-number">3</div><div class="dlm-nuance-text">Browser security policies can affect URL retrieval, especially with redirects or cross-origin navigation, causing unexpected URL values.</div></div></div><div class="dlm-when-not"><div class="dlm-when-not-label"><span class="new-material-symbols icon-hw-20"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="#EF4444"><path d="m480-433.33 124.67 124.66Q614.33-299 628-299q13.67 0 23.33-9.67Q661-318.33 661-332q0-13.67-9.67-23.33L526.67-480l124.66-124.67Q661-614.33 661-628q0-13.67-9.67-23.33Q641.67-661 628-661q-13.67 0-23.33 9.67L480-526.67 355.33-651.33Q345.67-661 332-661q-13.67 0-23.33 9.67Q299-641.67 299-628q0 13.67 9.67 23.33L433.33-480 308.67-355.33Q299-345.67 299-332q0 13.67 9.67 23.33Q318.33-299 332-299q13.67 0 23.33-9.67L480-433.33ZM480-80q-82.33 0-155.33-31.5-73-31.5-127.34-85.83Q143-251.67 111.5-324.67T80-480q0-83 31.5-156t85.83-127q54.34-54 127.34-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 82.33-31.5 155.33-31.5 73-85.5 127.34Q709-143 636-111.5T480-80Z"></path></svg></span>When NOT to use</div><div>Relying only on page title and URL is insufficient for complex pages with dynamic content or single-page applications. Instead, use element presence checks, JavaScript execution results, or network monitoring for deeper validation.</div></div><div class="dlm-production"><div class="dlm-production-label"><span class="new-material-symbols icon-hw-20"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="#10B981"><path d="m422-395.33-94-94q-9.67-9.67-24-9.67t-24.67 10.33q-9.66 9.67-9.66 24 0 14.34 9.66 24l119.34 120q10 10 23.33 10 13.33 0 23.33-10L680-555.33q10.33-10.34 10.33-24.67 0-14.33-10.33-24.67-10.33-9.66-25-9.33-14.67.33-24.33 10L422-395.33ZM480-80q-82.33 0-155.33-31.5-73-31.5-127.34-85.83Q143-251.67 111.5-324.67T80-480q0-83 31.5-156t85.83-127q54.34-54 127.34-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 82.33-31.5 155.33-31.5 73-85.5 127.34Q709-143 636-111.5T480-80Z"></path></svg></span>Production Patterns</div><div>In real-world tests, title and URL checks are combined with waits for page readiness and element visibility. Tests often use partial matches or regex for titles/URLs to handle dynamic parts. Also, these checks are part of navigation validation steps in end-to-end test suites.</div></div></div></article><article class="content-card dlm-card"><div class="code-articles-card-header"><span class="card-icon intro"><span class="new-material-symbols icon-hw-24"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="#3B82F6"><path d="M602.67-120v-123.33h-156V-650H358v126.67H80V-840h278v123.33h244.67V-840H880v316.67H602.67V-650h-89.34v340h89.34v-126.67H880V-120H602.67Zm-456-653.33V-590v-183.33ZM669.33-370v183.33V-370Zm0-403.33V-590v-183.33Zm0 183.33h144v-183.33h-144V-590Zm0 403.33h144V-370h-144v183.33ZM146.67-590h144.66v-183.33H146.67V-590Z"></path></svg></span></span><span class="codefly-card-title">Connections</span></div><div class="code-articles-card-body"><div class="dlm-connections-list"><div class="dlm-connection-item"><div class="dlm-connection-to">Assertions in Automated Testing</div><div class="dlm-connection-rel">Builds-on</div><div class="dlm-connection-insight"><span class="dlm-insight-icon"><svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 24 24" class="yellow-icon-color" height="22" width="22" xmlns="http://www.w3.org/2000/svg"><path d="M7.94101 18C7.64391 16.7274 6.30412 15.6857 5.75395 14.9992C4.65645 13.6297 4 11.8915 4 10C4 5.58172 7.58172 2 12 2C16.4183 2 20 5.58172 20 10C20 11.8925 19.3428 13.6315 18.2443 15.0014C17.6944 15.687 16.3558 16.7276 16.059 18H7.94101ZM16 20V21C16 22.1046 15.1046 23 14 23H10C8.89543 23 8 22.1046 8 21V20H16ZM13 10.0048V6L8.5 12.0048H11V16.0048L15.5 10.0048H13Z"></path></svg></span><span>Understanding how to retrieve page title and URL enables meaningful assertions that confirm navigation success in tests.</span></div></div><div class="dlm-connection-item"><div class="dlm-connection-to">WebDriver Waits and Synchronization</div><div class="dlm-connection-rel">Builds-on</div><div class="dlm-connection-insight"><span class="dlm-insight-icon"><svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 24 24" class="yellow-icon-color" height="22" width="22" xmlns="http://www.w3.org/2000/svg"><path d="M7.94101 18C7.64391 16.7274 6.30412 15.6857 5.75395 14.9992C4.65645 13.6297 4 11.8915 4 10C4 5.58172 7.58172 2 12 2C16.4183 2 20 5.58172 20 10C20 11.8925 19.3428 13.6315 18.2443 15.0014C17.6944 15.687 16.3558 16.7276 16.059 18H7.94101ZM16 20V21C16 22.1046 15.1046 23 14 23H10C8.89543 23 8 22.1046 8 21V20H16ZM13 10.0048V6L8.5 12.0048H11V16.0048L15.5 10.0048H13Z"></path></svg></span><span>Knowing that title and URL may not be immediately available teaches the importance of waits to avoid flaky tests.</span></div></div><div class="dlm-connection-item"><div class="dlm-connection-to">Package Labeling and Delivery Verification (Logistics)</div><div class="dlm-connection-rel">Analogy-based cross-domain</div><div class="dlm-connection-insight"><span class="dlm-insight-icon"><svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 24 24" class="yellow-icon-color" height="22" width="22" xmlns="http://www.w3.org/2000/svg"><path d="M7.94101 18C7.64391 16.7274 6.30412 15.6857 5.75395 14.9992C4.65645 13.6297 4 11.8915 4 10C4 5.58172 7.58172 2 12 2C16.4183 2 20 5.58172 20 10C20 11.8925 19.3428 13.6315 18.2443 15.0014C17.6944 15.687 16.3558 16.7276 16.059 18H7.94101ZM16 20V21C16 22.1046 15.1046 23 14 23H10C8.89543 23 8 22.1046 8 21V20H16ZM13 10.0048V6L8.5 12.0048H11V16.0048L15.5 10.0048H13Z"></path></svg></span><span>Just like checking a package label and address ensures correct delivery, verifying page title and URL ensures correct page navigation in testing.</span></div></div></div></div></article><article class="content-card dlm-card"><div class="code-articles-card-header"><span class="card-icon project"><span class="new-material-symbols icon-hw-24"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="#EF4444"><path d="m480-513.33 80.67 80.66Q570.33-423 584-423q13.67 0 23.33-9.67Q617-442.33 617-456q0-13.67-9.67-23.33L526.67-560l80.66-80.67Q617-650.33 617-664q0-13.67-9.67-23.33Q597.67-697 584-697q-13.67 0-23.33 9.67L480-606.67l-80.67-80.66Q389.67-697 376-697q-13.67 0-23.33 9.67Q343-677.67 343-664q0 13.67 9.67 23.33L433.33-560l-80.66 80.67Q343-469.67 343-456q0 13.67 9.67 23.33Q362.33-423 376-423q13.67 0 23.33-9.67L480-513.33ZM240-240 136.67-136.67Q121-121 100.5-129.6 80-138.21 80-160.33v-653q0-27 19.83-46.84Q119.67-880 146.67-880h666.66q27 0 46.84 19.83Q880-840.33 880-813.33v506.66q0 27-19.83 46.84Q840.33-240 813.33-240H240Zm-28.67-66.67h602v-506.66H146.67v575l64.66-68.34Zm-64.66 0v-506.66 506.66Z"></path></svg></span></span><span class="codefly-card-title">Common Pitfalls</span></div><div class="code-articles-card-body"><div class="dlm-pitfalls-list"><div class="dlm-pitfall-item"><div class="dlm-pitfall-header"><span class="dlm-pitfall-number">#<!-- -->1</span><span class="dlm-pitfall-title">Checking page title immediately after navigation without waiting.</span></div><div class="dlm-pitfall-body"><div class="dlm-pitfall-wrong"><span class="dlm-pitfall-label"><span class="new-material-symbols icon-hw-20"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="#EF4444"><path d="m480-433.33 124.67 124.66Q614.33-299 628-299q13.67 0 23.33-9.67Q661-318.33 661-332q0-13.67-9.67-23.33L526.67-480l124.66-124.67Q661-614.33 661-628q0-13.67-9.67-23.33Q641.67-661 628-661q-13.67 0-23.33 9.67L480-526.67 355.33-651.33Q345.67-661 332-661q-13.67 0-23.33 9.67Q299-641.67 299-628q0 13.67 9.67 23.33L433.33-480 308.67-355.33Q299-345.67 299-332q0 13.67 9.67 23.33Q318.33-299 332-299q13.67 0 23.33-9.67L480-433.33ZM480-80q-82.33 0-155.33-31.5-73-31.5-127.34-85.83Q143-251.67 111.5-324.67T80-480q0-83 31.5-156t85.83-127q54.34-54 127.34-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 82.33-31.5 155.33-31.5 73-85.5 127.34Q709-143 636-111.5T480-80Z"></path></svg></span>Wrong approach:</span><span>driver.get("https://example.com"); String title = driver.getTitle(); assertEquals("Example Domain", title);</span></div><div class="dlm-pitfall-right"><span class="dlm-pitfall-label"><span class="new-material-symbols icon-hw-20"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="#10B981"><path d="m422-395.33-94-94q-9.67-9.67-24-9.67t-24.67 10.33q-9.66 9.67-9.66 24 0 14.34 9.66 24l119.34 120q10 10 23.33 10 13.33 0 23.33-10L680-555.33q10.33-10.34 10.33-24.67 0-14.33-10.33-24.67-10.33-9.66-25-9.33-14.67.33-24.33 10L422-395.33ZM480-80q-82.33 0-155.33-31.5-73-31.5-127.34-85.83Q143-251.67 111.5-324.67T80-480q0-83 31.5-156t85.83-127q54.34-54 127.34-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 82.33-31.5 155.33-31.5 73-85.5 127.34Q709-143 636-111.5T480-80Z"></path></svg></span>Correct approach:</span><span>driver.get("https://example.com"); new WebDriverWait(driver, Duration.ofSeconds(10)) .until(ExpectedConditions.titleIs("Example Domain")); String title = driver.getTitle(); assertEquals("Example Domain", title);</span></div><div class="dlm-pitfall-root"><span class="dlm-pitfall-label"><span class="new-material-symbols icon-hw-20"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="#3B82F6"><path d="M400-320q100 0 170-70t70-170q0-100-70-170t-170-70q-100 0-170 70t-70 170q0 100 70 170t170 70Zm-28.5-131.5Q360-463 360-480v-200q0-17 11.5-28.5T400-720q17 0 28.5 11.5T440-680v200q0 17-11.5 28.5T400-440q-17 0-28.5-11.5Zm-140 0Q220-463 220-480v-120q0-17 11.5-28.5T260-640q17 0 28.5 11.5T300-600v120q0 17-11.5 28.5T260-440q-17 0-28.5-11.5Zm280 0Q500-463 500-480v-80q0-17 11.5-28.5T540-600q17 0 28.5 11.5T580-560v80q0 17-11.5 28.5T540-440q-17 0-28.5-11.5ZM400-240q-134 0-227-93T80-560q0-134 93-227t227-93q134 0 227 93t93 227q0 56-17.5 106T653-363l199 199q11 11 11 28t-11 28q-11 11-28 11t-28-11L597-307q-41 32-91 49.5T400-240Z"></path></svg></span>Root cause:</span><span>The test tries to get the title before the page finishes loading, causing flaky failures.</span></div></div></div><div class="dlm-pitfall-item"><div class="dlm-pitfall-header"><span class="dlm-pitfall-number">#<!-- -->2</span><span class="dlm-pitfall-title">Using exact string match for URLs that include dynamic query parameters.</span></div><div class="dlm-pitfall-body"><div class="dlm-pitfall-wrong"><span class="dlm-pitfall-label"><span class="new-material-symbols icon-hw-20"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="#EF4444"><path d="m480-433.33 124.67 124.66Q614.33-299 628-299q13.67 0 23.33-9.67Q661-318.33 661-332q0-13.67-9.67-23.33L526.67-480l124.66-124.67Q661-614.33 661-628q0-13.67-9.67-23.33Q641.67-661 628-661q-13.67 0-23.33 9.67L480-526.67 355.33-651.33Q345.67-661 332-661q-13.67 0-23.33 9.67Q299-641.67 299-628q0 13.67 9.67 23.33L433.33-480 308.67-355.33Q299-345.67 299-332q0 13.67 9.67 23.33Q318.33-299 332-299q13.67 0 23.33-9.67L480-433.33ZM480-80q-82.33 0-155.33-31.5-73-31.5-127.34-85.83Q143-251.67 111.5-324.67T80-480q0-83 31.5-156t85.83-127q54.34-54 127.34-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 82.33-31.5 155.33-31.5 73-85.5 127.34Q709-143 636-111.5T480-80Z"></path></svg></span>Wrong approach:</span><span>assertEquals("https://example.com/page?session=123", driver.getCurrentUrl());</span></div><div class="dlm-pitfall-right"><span class="dlm-pitfall-label"><span class="new-material-symbols icon-hw-20"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="#10B981"><path d="m422-395.33-94-94q-9.67-9.67-24-9.67t-24.67 10.33q-9.66 9.67-9.66 24 0 14.34 9.66 24l119.34 120q10 10 23.33 10 13.33 0 23.33-10L680-555.33q10.33-10.34 10.33-24.67 0-14.33-10.33-24.67-10.33-9.66-25-9.33-14.67.33-24.33 10L422-395.33ZM480-80q-82.33 0-155.33-31.5-73-31.5-127.34-85.83Q143-251.67 111.5-324.67T80-480q0-83 31.5-156t85.83-127q54.34-54 127.34-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 82.33-31.5 155.33-31.5 73-85.5 127.34Q709-143 636-111.5T480-80Z"></path></svg></span>Correct approach:</span><span>assertTrue(driver.getCurrentUrl().startsWith("https://example.com/page"));</span></div><div class="dlm-pitfall-root"><span class="dlm-pitfall-label"><span class="new-material-symbols icon-hw-20"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="#3B82F6"><path d="M400-320q100 0 170-70t70-170q0-100-70-170t-170-70q-100 0-170 70t-70 170q0 100 70 170t170 70Zm-28.5-131.5Q360-463 360-480v-200q0-17 11.5-28.5T400-720q17 0 28.5 11.5T440-680v200q0 17-11.5 28.5T400-440q-17 0-28.5-11.5Zm-140 0Q220-463 220-480v-120q0-17 11.5-28.5T260-640q17 0 28.5 11.5T300-600v120q0 17-11.5 28.5T260-440q-17 0-28.5-11.5Zm280 0Q500-463 500-480v-80q0-17 11.5-28.5T540-600q17 0 28.5 11.5T580-560v80q0 17-11.5 28.5T540-440q-17 0-28.5-11.5ZM400-240q-134 0-227-93T80-560q0-134 93-227t227-93q134 0 227 93t93 227q0 56-17.5 106T653-363l199 199q11 11 11 28t-11 28q-11 11-28 11t-28-11L597-307q-41 32-91 49.5T400-240Z"></path></svg></span>Root cause:</span><span>Dynamic parts of the URL cause exact matches to fail unnecessarily.</span></div></div></div><div class="dlm-pitfall-item"><div class="dlm-pitfall-header"><span class="dlm-pitfall-number">#<!-- -->3</span><span class="dlm-pitfall-title">Assuming getTitle() returns visible page content.</span></div><div class="dlm-pitfall-body"><div class="dlm-pitfall-wrong"><span class="dlm-pitfall-label"><span class="new-material-symbols icon-hw-20"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="#EF4444"><path d="m480-433.33 124.67 124.66Q614.33-299 628-299q13.67 0 23.33-9.67Q661-318.33 661-332q0-13.67-9.67-23.33L526.67-480l124.66-124.67Q661-614.33 661-628q0-13.67-9.67-23.33Q641.67-661 628-661q-13.67 0-23.33 9.67L480-526.67 355.33-651.33Q345.67-661 332-661q-13.67 0-23.33 9.67Q299-641.67 299-628q0 13.67 9.67 23.33L433.33-480 308.67-355.33Q299-345.67 299-332q0 13.67 9.67 23.33Q318.33-299 332-299q13.67 0 23.33-9.67L480-433.33ZM480-80q-82.33 0-155.33-31.5-73-31.5-127.34-85.83Q143-251.67 111.5-324.67T80-480q0-83 31.5-156t85.83-127q54.34-54 127.34-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 82.33-31.5 155.33-31.5 73-85.5 127.34Q709-143 636-111.5T480-80Z"></path></svg></span>Wrong approach:</span><span>String title = driver.getTitle(); assertTrue(title.contains("Welcome Message")); // expecting visible text</span></div><div class="dlm-pitfall-right"><span class="dlm-pitfall-label"><span class="new-material-symbols icon-hw-20"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="#10B981"><path d="m422-395.33-94-94q-9.67-9.67-24-9.67t-24.67 10.33q-9.66 9.67-9.66 24 0 14.34 9.66 24l119.34 120q10 10 23.33 10 13.33 0 23.33-10L680-555.33q10.33-10.34 10.33-24.67 0-14.33-10.33-24.67-10.33-9.66-25-9.33-14.67.33-24.33 10L422-395.33ZM480-80q-82.33 0-155.33-31.5-73-31.5-127.34-85.83Q143-251.67 111.5-324.67T80-480q0-83 31.5-156t85.83-127q54.34-54 127.34-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 82.33-31.5 155.33-31.5 73-85.5 127.34Q709-143 636-111.5T480-80Z"></path></svg></span>Correct approach:</span><span>String pageText = driver.findElement(By.tagName("body")).getText(); assertTrue(pageText.contains("Welcome Message"));</span></div><div class="dlm-pitfall-root"><span class="dlm-pitfall-label"><span class="new-material-symbols icon-hw-20"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="#3B82F6"><path d="M400-320q100 0 170-70t70-170q0-100-70-170t-170-70q-100 0-170 70t-70 170q0 100 70 170t170 70Zm-28.5-131.5Q360-463 360-480v-200q0-17 11.5-28.5T400-720q17 0 28.5 11.5T440-680v200q0 17-11.5 28.5T400-440q-17 0-28.5-11.5Zm-140 0Q220-463 220-480v-120q0-17 11.5-28.5T260-640q17 0 28.5 11.5T300-600v120q0 17-11.5 28.5T260-440q-17 0-28.5-11.5Zm280 0Q500-463 500-480v-80q0-17 11.5-28.5T540-600q17 0 28.5 11.5T580-560v80q0 17-11.5 28.5T540-440q-17 0-28.5-11.5ZM400-240q-134 0-227-93T80-560q0-134 93-227t227-93q134 0 227 93t93 227q0 56-17.5 106T653-363l199 199q11 11 11 28t-11 28q-11 11-28 11t-28-11L597-307q-41 32-91 49.5T400-240Z"></path></svg></span>Root cause:</span><span>Confusing the page title with visible page text leads to wrong assertions.</span></div></div></div></div></div></article><article class="content-card dlm-card"><div class="code-articles-card-header"><span class="card-icon summary"><span class="new-material-symbols icon-hw-24"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="#10B981"><path d="M186.67-120q-27.5 0-47.09-19.58Q120-159.17 120-186.67v-586.66q0-27.5 19.58-47.09Q159.17-840 186.67-840h192.66q7.67-35.33 35.84-57.67Q443.33-920 480-920t64.83 22.33Q573-875.33 580.67-840h192.66q27.5 0 47.09 19.58Q840-800.83 840-773.33v586.66q0 27.5-19.58 47.09Q800.83-120 773.33-120H186.67Zm0-66.67h586.66v-586.66H186.67v586.66ZM313.33-280H522q14.17 0 23.75-9.62 9.58-9.61 9.58-23.83 0-14.22-9.58-23.72-9.58-9.5-23.75-9.5H313.33q-14.16 0-23.75 9.62-9.58 9.62-9.58 23.83 0 14.22 9.58 23.72 9.59 9.5 23.75 9.5Zm0-166.67h333.34q14.16 0 23.75-9.61 9.58-9.62 9.58-23.84 0-14.21-9.58-23.71-9.59-9.5-23.75-9.5H313.33q-14.16 0-23.75 9.61-9.58 9.62-9.58 23.84 0 14.21 9.58 23.71 9.59 9.5 23.75 9.5Zm0-166.66h333.34q14.16 0 23.75-9.62 9.58-9.62 9.58-23.83 0-14.22-9.58-23.72-9.59-9.5-23.75-9.5H313.33q-14.16 0-23.75 9.62-9.58 9.61-9.58 23.83 0 14.22 9.58 23.72 9.59 9.5 23.75 9.5ZM503.5-804.5q9.83-9.83 9.83-23.5t-9.83-23.5q-9.83-9.83-23.5-9.83t-23.5 9.83q-9.83 9.83-9.83 23.5t9.83 23.5q9.83 9.83 23.5 9.83t23.5-9.83ZM186.67-186.67v-586.66 586.66Z"></path></svg></span></span><span class="codefly-card-title">Key Takeaways</span></div><div class="code-articles-card-body"><div class="summary-list"><div class="summary-item"><span class="new-material-symbols icon-hw-26"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="#10B981"><path d="m422-395.33-94-94q-9.67-9.67-24-9.67t-24.67 10.33q-9.66 9.67-9.66 24 0 14.34 9.66 24l119.34 120q10 10 23.33 10 13.33 0 23.33-10L680-555.33q10.33-10.34 10.33-24.67 0-14.33-10.33-24.67-10.33-9.66-25-9.33-14.67.33-24.33 10L422-395.33ZM480-80q-82.33 0-155.33-31.5-73-31.5-127.34-85.83Q143-251.67 111.5-324.67T80-480q0-83 31.5-156t85.83-127q54.34-54 127.34-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 82.33-31.5 155.33-31.5 73-85.5 127.34Q709-143 636-111.5T480-80Z"></path></svg></span><span class="summary-text">Page title and URL retrieval are fundamental checks to confirm correct page navigation in automated web tests.</span></div><div class="summary-item"><span class="new-material-symbols icon-hw-26"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="#10B981"><path d="m422-395.33-94-94q-9.67-9.67-24-9.67t-24.67 10.33q-9.66 9.67-9.66 24 0 14.34 9.66 24l119.34 120q10 10 23.33 10 13.33 0 23.33-10L680-555.33q10.33-10.34 10.33-24.67 0-14.33-10.33-24.67-10.33-9.66-25-9.33-14.67.33-24.33 10L422-395.33ZM480-80q-82.33 0-155.33-31.5-73-31.5-127.34-85.83Q143-251.67 111.5-324.67T80-480q0-83 31.5-156t85.83-127q54.34-54 127.34-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 82.33-31.5 155.33-31.5 73-85.5 127.34Q709-143 636-111.5T480-80Z"></path></svg></span><span class="summary-text">Selenium WebDriver provides simple methods getTitle() and getCurrentUrl() that return strings representing the current page's title and URL.</span></div><div class="summary-item"><span class="new-material-symbols icon-hw-26"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="#10B981"><path d="m422-395.33-94-94q-9.67-9.67-24-9.67t-24.67 10.33q-9.66 9.67-9.66 24 0 14.34 9.66 24l119.34 120q10 10 23.33 10 13.33 0 23.33-10L680-555.33q10.33-10.34 10.33-24.67 0-14.33-10.33-24.67-10.33-9.66-25-9.33-14.67.33-24.33 10L422-395.33ZM480-80q-82.33 0-155.33-31.5-73-31.5-127.34-85.83Q143-251.67 111.5-324.67T80-480q0-83 31.5-156t85.83-127q54.34-54 127.34-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 82.33-31.5 155.33-31.5 73-85.5 127.34Q709-143 636-111.5T480-80Z"></path></svg></span><span class="summary-text">Always wait for the page to load fully before retrieving title or URL to avoid flaky tests.</span></div><div class="summary-item"><span class="new-material-symbols icon-hw-26"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="#10B981"><path d="m422-395.33-94-94q-9.67-9.67-24-9.67t-24.67 10.33q-9.66 9.67-9.66 24 0 14.34 9.66 24l119.34 120q10 10 23.33 10 13.33 0 23.33-10L680-555.33q10.33-10.34 10.33-24.67 0-14.33-10.33-24.67-10.33-9.66-25-9.33-14.67.33-24.33 10L422-395.33ZM480-80q-82.33 0-155.33-31.5-73-31.5-127.34-85.83Q143-251.67 111.5-324.67T80-480q0-83 31.5-156t85.83-127q54.34-54 127.34-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 82.33-31.5 155.33-31.5 73-85.5 127.34Q709-143 636-111.5T480-80Z"></path></svg></span><span class="summary-text">Use assertions to compare retrieved title and URL with expected values, but handle dynamic content flexibly.</span></div><div class="summary-item"><span class="new-material-symbols icon-hw-26"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="#10B981"><path d="m422-395.33-94-94q-9.67-9.67-24-9.67t-24.67 10.33q-9.66 9.67-9.66 24 0 14.34 9.66 24l119.34 120q10 10 23.33 10 13.33 0 23.33-10L680-555.33q10.33-10.34 10.33-24.67 0-14.33-10.33-24.67-10.33-9.66-25-9.33-14.67.33-24.33 10L422-395.33ZM480-80q-82.33 0-155.33-31.5-73-31.5-127.34-85.83Q143-251.67 111.5-324.67T80-480q0-83 31.5-156t85.83-127q54.34-54 127.34-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 82.33-31.5 155.33-31.5 73-85.5 127.34Q709-143 636-111.5T480-80Z"></path></svg></span><span class="summary-text">Title and URL checks alone are not enough; combine them with other validations for robust test coverage.</span></div></div></div></article></div></div></main><div style="position:fixed;bottom:24px;right:24px;z-index:50"><button style="background:rgba(255,255,255,0.95);border:1px solid rgba(108,99,255,0.18);border-radius:10px;padding:10px 16px;color:#5f56fe;font-size:14px;cursor:pointer;display:flex;align-items:center;gap:7px;backdrop-filter:blur(12px);box-shadow:0 2px 12px rgba(0,0,0,0.08), 0 0 0 1px rgba(108,99,255,0.06);transition:all 0.2s"><span style="font-size:14px">⚑</span>Report Issue</button></div></div> <script src="/_next/static/chunks/webpack-fd24bd8e19d2841a.js" async=""></script><script>(self.__next_f=self.__next_f||[]).push([0]);self.__next_f.push([2,null])</script><script>self.__next_f.push([1,"1:HL[\"/_next/static/css/b133bdac07c7940e.css\",\"style\"]\n2:HL[\"/_next/static/css/837a603cb1a59856.css\",\"style\"]\n3:HL[\"/_next/static/css/725c7861d1898ba8.css\",\"style\"]\n4:HL[\"/_next/static/css/caf3ca742c7945f9.css\",\"style\"]\n"])</script><script>self.__next_f.push([1,"5:I[95751,[],\"\"]\n8:I[39275,[],\"\"]\ne:I[61343,[],\"\"]\nf:I[84080,[\"8726\",\"static/chunks/8726-583188341cbc1496.js\",\"3185\",\"static/chunks/app/layout-7a1373330f6a4c98.js\"],\"\"]\n10:I[88726,[\"8726\",\"static/chunks/8726-583188341cbc1496.js\",\"3185\",\"static/chunks/app/layout-7a1373330f6a4c98.js\"],\"Toaster\"]\n11:I[20154,[\"8422\",\"static/chunks/66ec4792-a0fc378024be0c7b.js\",\"6648\",\"static/chunks/6648-fff0cf0e0a1f8d25.js\",\"9160\",\"static/chunks/app/not-found-c4181ddc3e64e5f3.js\"],\"default\"]\n12:I[70548,[\"8726\",\"static/chunks/8726-583188341cbc1496.js\",\"3185\",\"static/chunks/app/layout-7a1373330f6a4c98.js\"],\"default\"]\n14:I[76130,[],\"\"]\n9:[\"lang\",\"en\",\"d\"]\na:[\"subject\",\"selenium-java\",\"d\"]\nb:[\"part\",\"part-1\",\"d\"]\nc:[\"pattern\",\"selenium-java-page-title-and-url-retrieval\",\"d\"]\nd:[\"mode\",\"deep\",\"oc\"]\n15:[]\n"])</script><script>self.__next_f.push([1,"0:[[[\"$\",\"link\",\"0\",{\"rel\":\"stylesheet\",\"href\":\"/_next/static/css/b133bdac07c7940e.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}]],[\"$\",\"$L5\",null,{\"buildId\":\"hN8t5By7h5nzsrdSose07\",\"assetPrefix\":\"\",\"initialCanonicalUrl\":\"/en/codefly/learn/selenium-java/part-1/selenium-java-page-title-and-url-retrieval/deep\",\"initialTree\":[\"\",{\"children\":[[\"lang\",\"en\",\"d\"],{\"children\":[\"codefly\",{\"children\":[\"learn\",{\"children\":[[\"subject\",\"selenium-java\",\"d\"],{\"children\":[[\"part\",\"part-1\",\"d\"],{\"children\":[[\"pattern\",\"selenium-java-page-title-and-url-retrieval\",\"d\"],{\"children\":[[\"mode\",\"deep\",\"oc\"],{\"children\":[\"__PAGE__\",{}]}]}]}]}]}]}]}]},\"$undefined\",\"$undefined\",true],\"initialSeedData\":[\"\",{\"children\":[[\"lang\",\"en\",\"d\"],{\"children\":[\"codefly\",{\"children\":[\"learn\",{\"children\":[[\"subject\",\"selenium-java\",\"d\"],{\"children\":[[\"part\",\"part-1\",\"d\"],{\"children\":[[\"pattern\",\"selenium-java-page-title-and-url-retrieval\",\"d\"],{\"children\":[[\"mode\",\"deep\",\"oc\"],{\"children\":[\"__PAGE__\",{},[[\"$L6\",\"$L7\"],null],null]},[\"$\",\"$L8\",null,{\"parallelRouterKey\":\"children\",\"segmentPath\":[\"children\",\"$9\",\"children\",\"codefly\",\"children\",\"learn\",\"children\",\"$a\",\"children\",\"$b\",\"children\",\"$c\",\"children\",\"$d\",\"children\"],\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$Le\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":\"$undefined\",\"notFoundStyles\":\"$undefined\",\"styles\":[[\"$\",\"link\",\"0\",{\"rel\":\"stylesheet\",\"href\":\"/_next/static/css/837a603cb1a59856.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}],[\"$\",\"link\",\"1\",{\"rel\":\"stylesheet\",\"href\":\"/_next/static/css/725c7861d1898ba8.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}],[\"$\",\"link\",\"2\",{\"rel\":\"stylesheet\",\"href\":\"/_next/static/css/caf3ca742c7945f9.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}]]}],null]},[\"$\",\"$L8\",null,{\"parallelRouterKey\":\"children\",\"segmentPath\":[\"children\",\"$9\",\"children\",\"codefly\",\"children\",\"learn\",\"children\",\"$a\",\"children\",\"$b\",\"children\",\"$c\",\"children\"],\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$Le\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":\"$undefined\",\"notFoundStyles\":\"$undefined\",\"styles\":null}],null]},[\"$\",\"$L8\",null,{\"parallelRouterKey\":\"children\",\"segmentPath\":[\"children\",\"$9\",\"children\",\"codefly\",\"children\",\"learn\",\"children\",\"$a\",\"children\",\"$b\",\"children\"],\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$Le\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":\"$undefined\",\"notFoundStyles\":\"$undefined\",\"styles\":null}],null]},[\"$\",\"$L8\",null,{\"parallelRouterKey\":\"children\",\"segmentPath\":[\"children\",\"$9\",\"children\",\"codefly\",\"children\",\"learn\",\"children\",\"$a\",\"children\"],\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$Le\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":\"$undefined\",\"notFoundStyles\":\"$undefined\",\"styles\":null}],null]},[\"$\",\"$L8\",null,{\"parallelRouterKey\":\"children\",\"segmentPath\":[\"children\",\"$9\",\"children\",\"codefly\",\"children\",\"learn\",\"children\"],\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$Le\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":\"$undefined\",\"notFoundStyles\":\"$undefined\",\"styles\":null}],null]},[\"$\",\"$L8\",null,{\"parallelRouterKey\":\"children\",\"segmentPath\":[\"children\",\"$9\",\"children\",\"codefly\",\"children\"],\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$Le\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":\"$undefined\",\"notFoundStyles\":\"$undefined\",\"styles\":null}],null]},[\"$\",\"$L8\",null,{\"parallelRouterKey\":\"children\",\"segmentPath\":[\"children\",\"$9\",\"children\"],\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$Le\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":\"$undefined\",\"notFoundStyles\":\"$undefined\",\"styles\":null}],null]},[[\"$\",\"html\",null,{\"lang\":\"en\",\"children\":[[\"$\",\"head\",null,{\"children\":[[\"$\",\"meta\",null,{\"name\":\"theme-color\",\"content\":\"#5f56fe\"}],[\"$\",\"meta\",null,{\"name\":\"msapplication-TileColor\",\"content\":\"#5f56fe\"}],[\"$\",\"$Lf\",null,{\"src\":\"https://www.googletagmanager.com/gtag/js?id=G-N2NY2DMMDW\",\"strategy\":\"afterInteractive\"}],[\"$\",\"$Lf\",null,{\"id\":\"google-analytics\",\"strategy\":\"afterInteractive\",\"children\":\"\\n window.dataLayer = window.dataLayer || [];\\n function gtag(){dataLayer.push(arguments);}\\n gtag('js', new Date());\\n gtag('config', 'G-N2NY2DMMDW', {\\n page_path: window.location.pathname,\\n });\\n \"}],[\"$\",\"script\",null,{\"async\":true,\"src\":\"https://www.googletagmanager.com/gtag/js?id=AW-17928224938\"}],[\"$\",\"$Lf\",null,{\"children\":\"\\n window.dataLayer = window.dataLayer || [];\\n function gtag() {\\n dataLayer.push(arguments);\\n }\\n gtag('js', new Date());\\n gtag('config', 'AW-17928224938');\\n \"}],[\"$\",\"script\",null,{\"data-grow-initializer\":\"\",\"suppressHydrationWarning\":true,\"dangerouslySetInnerHTML\":{\"__html\":\"!(function(){window.growMe||((window.growMe=function(e){window.growMe._.push(e);}),(window.growMe._=[]));var e=document.createElement(\\\"script\\\");(e.type=\\\"text/javascript\\\"),(e.src=\\\"https://faves.grow.me/main.js\\\"),(e.defer=!0),e.setAttribute(\\\"data-grow-faves-site-id\\\",\\\"U2l0ZTo0MGIxZDBlZC0wNzdlLTQ0NjgtOThmOC1kNDYyZGMwM2IwMWY=\\\");var t=document.getElementsByTagName(\\\"script\\\")[0];t.parentNode.insertBefore(e,t);})();\"}}],[\"$\",\"$Lf\",null,{\"src\":\"//scripts.scriptwrapper.com/tags/40b1d0ed-077e-4468-98f8-d462dc03b01f.js\",\"strategy\":\"afterInteractive\",\"data-noptimize\":\"1\",\"data-cfasync\":\"false\"}],[\"$\",\"script\",null,{\"type\":\"application/ld+json\",\"suppressHydrationWarning\":true,\"dangerouslySetInnerHTML\":{\"__html\":\"{\\\"@context\\\":\\\"https://schema.org\\\",\\\"@type\\\":\\\"WebApplication\\\",\\\"name\\\":\\\"Leyaa.ai\\\",\\\"description\\\":\\\"Leyaa.ai builds learning intelligence that understands how you learn - guiding what to study, how to practice, and when to move forward.\\\",\\\"url\\\":\\\"https://leyaa.ai\\\",\\\"applicationCategory\\\":\\\"EducationalApplication\\\",\\\"operatingSystem\\\":\\\"Web\\\",\\\"offers\\\":{\\\"@type\\\":\\\"Offer\\\",\\\"price\\\":\\\"0\\\",\\\"priceCurrency\\\":\\\"USD\\\"},\\\"creator\\\":{\\\"@type\\\":\\\"Organization\\\",\\\"name\\\":\\\"Leyaa.ai\\\"}}\"}}],[\"$\",\"link\",null,{\"href\":\"https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css\",\"rel\":\"stylesheet\",\"integrity\":\"sha384-sRIl4kxILFvY47J16cr9ZwB07vP4J8+LH7qKQnuqkuIAvNWLzeN8tE5YBujZqJLB\",\"crossOrigin\":\"anonymous\"}],[\"$\",\"$Lf\",null,{\"id\":\"clarity-script\",\"strategy\":\"afterInteractive\",\"dangerouslySetInnerHTML\":{\"__html\":\"\\n (function(c,l,a,r,i,t,y){\\n c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};\\n t=l.createElement(r);t.async=1;t.src=\\\"https://www.clarity.ms/tag/\\\"+i;\\n y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);\\n })(window, document, \\\"clarity\\\", \\\"script\\\", \\\"w4gxh6rdmh\\\");\\n \"}}]]}],[\"$\",\"body\",null,{\"children\":[[\"$\",\"$L10\",null,{\"containerStyle\":{\"top\":70}}],[\"$\",\"div\",null,{\"className\":\"bg-grid\"}],[\"$\",\"$L8\",null,{\"parallelRouterKey\":\"children\",\"segmentPath\":[\"children\"],\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$Le\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":[\"$\",\"$L11\",null,{}],\"notFoundStyles\":[[\"$\",\"link\",\"0\",{\"rel\":\"stylesheet\",\"href\":\"/_next/static/css/250d3fff07338fa3.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}]],\"styles\":null}],[\"$\",\"$L12\",null,{}],\" \"]}]]}],null],null],\"couldBeIntercepted\":false,\"initialHead\":[false,\"$L13\"],\"globalErrorComponent\":\"$14\",\"missingSlots\":\"$W15\"}]]\n"])</script><script>self.__next_f.push([1,"17:I[51766,[\"8422\",\"static/chunks/66ec4792-a0fc378024be0c7b.js\",\"522\",\"static/chunks/94730671-fd9628eddbd5107b.js\",\"7240\",\"static/chunks/53c13509-506edbde2b5b3f55.js\",\"7699\",\"static/chunks/8e1d74a4-a085c2fbc868135a.js\",\"5706\",\"static/chunks/9c4e2130-11ecd4bfc78e4568.js\",\"1779\",\"static/chunks/0e762574-6b3bda54d2fd2e14.js\",\"6648\",\"static/chunks/6648-fff0cf0e0a1f8d25.js\",\"3463\",\"static/chunks/3463-09ee572e3d7819a2.js\",\"4889\",\"static/chunks/4889-956a916919971629.js\",\"9985\",\"static/chunks/9985-b39235669d2563e2.js\",\"7627\",\"static/chunks/7627-224bb765a4decf1d.js\",\"7652\",\"static/chunks/7652-412e201fe52797ee.js\",\"8935\",\"static/chunks/8935-c1c159349bf7da40.js\",\"9663\",\"static/chunks/9663-fdcd080af3916e3e.js\",\"7029\",\"static/chunks/app/%5Blang%5D/codefly/learn/%5Bsubject%5D/%5Bpart%5D/%5Bpattern%5D/%5B%5B...mode%5D%5D/page-1fc9c577a9450e06.js\"],\"default\"]\n16:T429,{\"@context\":\"https://schema.org\",\"@type\":\"LearningResource\",\"name\":\"Page title and URL retrieval in Selenium Java - Deep Dive\",\"description\":\"Go deep on Page title and URL retrieval in Selenium Java. Internals, mental models, under-the-hood mechanics, misconceptions, common pitfalls, and production patterns. For serious learners.\",\"url\":\"https://leyaa.ai/codefly/learn/selenium-java/part-1/selenium-java-page-title-and-url-retrieval\",\"learningResourceType\":\"Tutorial\",\"programmingLanguage\":\"Selenium Java\",\"inLanguage\":\"en\",\"isAccessibleForFree\":true,\"teaches\":\"Page title and URL retrieval in Selenium Java - Deep Dive\",\"provider\":{\"@type\":\"Organization\",\"url\":\"https://leyaa.ai\"},\"educationalLevel\":\"Beginner to Advanced\",\"breadcrumb\":{\"@type\":\"BreadcrumbList\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https://leyaa.ai\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Page title and URL retrieval in Selenium Java - Deep Dive\",\"item\":\"https://leyaa.ai/codefly/learn/selenium-java/part-1/selenium-java-page-title-and-url-retrieval\"}]}}"])</script><script>self.__next_f.push([1,"7:[[[\"$\",\"script\",\"0\",{\"type\":\"application/ld+json\",\"dangerouslySetInnerHTML\":{\"__html\":\"$16\"}}]],[\"$\",\"$L17\",null,{\"subject\":\"selenium-java\",\"dbSubject\":\"selenium_java\",\"part\":\"part-1\",\"pattern\":\"selenium_java_page_title_and_url_retrieval\",\"modeSlug\":\"deep\",\"lang\":\"en\",\"internalLinks\":[{\"code\":\"LMC\",\"slug\":\"\",\"label\":\"📖 Learn\",\"href\":\"/codefly/learn/selenium-java/part-1/selenium-java-page-title-and-url-retrieval\",\"active\":false},{\"code\":\"LMCWHY\",\"slug\":\"why\",\"label\":\"💡 Why Learn This\",\"href\":\"/codefly/learn/selenium-java/part-1/selenium-java-page-title-and-url-retrieval/why\",\"active\":false},{\"code\":\"DLM\",\"slug\":\"deep\",\"label\":\"💡 Deep Learn Mode\",\"href\":\"/codefly/learn/selenium-java/part-1/selenium-java-page-title-and-url-retrieval/deep\",\"active\":true},{\"code\":\"TMC\",\"slug\":\"try\",\"label\":\"✏️ Try It\",\"href\":\"/codefly/learn/selenium-java/part-1/selenium-java-page-title-and-url-retrieval/try\",\"active\":false},{\"code\":\"VMC\",\"slug\":\"visualize\",\"label\":\"👁 Visualize\",\"href\":\"/codefly/learn/selenium-java/part-1/selenium-java-page-title-and-url-retrieval/visualize\",\"active\":false},{\"code\":\"TCM\",\"slug\":\"complexity\",\"label\":\"⏱ Complexity\",\"href\":\"/codefly/learn/selenium-java/part-1/selenium-java-page-title-and-url-retrieval/complexity\",\"active\":false},{\"code\":\"CMC\",\"slug\":\"challenge\",\"label\":\"🏆 Challenge\",\"href\":\"/codefly/learn/selenium-java/part-1/selenium-java-page-title-and-url-retrieval/challenge\",\"active\":false},{\"code\":\"PMC\",\"slug\":\"project\",\"label\":\"📁 Project\",\"href\":\"/codefly/learn/selenium-java/part-1/selenium-java-page-title-and-url-retrieval/project\",\"active\":false},{\"code\":\"RMC\",\"slug\":\"review\",\"label\":\"🧠 Quick Review\",\"href\":\"/codefly/learn/selenium-java/part-1/selenium-java-page-title-and-url-retrieval/review\",\"active\":false}],\"isLoggedIn\":false,\"seoH1\":\"Page title and URL retrieval in Selenium Java - Deep Dive\",\"contentData\":{\"pattern_id\":\"selenium_java_page_title_and_url_retrieval\",\"metadata\":{\"slot_map\":{\"LMCWHY\":\"LMCWHY\",\"LMC\":\"LMC\",\"TMC\":\"TMC\",\"CMC\":\"CMC\",\"RMC\":\"RMC\",\"VMC\":\"EXC\",\"TCM\":\"TFW\",\"PMC\":\"AUT\",\"DLM\":\"DLM\"}},\"modes\":{\"DLM\":{\"topic\":\"Page title and URL retrieval\",\"mode\":\"DLM_v1\",\"language\":\"selenium_java\",\"content_type\":\"Software Testing \u0026 QA\",\"overview\":{\"what\":\"Page title and URL retrieval means getting the current web page's title and its web address (URL) using automated tests. In Selenium with Java, this helps verify that the browser is showing the right page during testing. The title is the text shown on the browser tab, and the URL is the exact address in the browser's address bar. These are basic but important checks in web testing.\",\"why_it_matters\":\"Without checking the page title and URL, tests might miss if the browser navigated to the wrong page or if the page loaded incorrectly. This can cause bugs to go unnoticed, leading to bad user experiences or broken features. Retrieving and verifying these values ensures the website behaves as expected and helps catch navigation errors early.\",\"where_it_fits\":\"Before learning this, you should know how to set up Selenium WebDriver and open a web page. After this, you can learn more about interacting with page elements, waiting for page loads, and validating page content. This topic is a foundation for verifying navigation and page correctness in automated tests.\"},\"mental_model\":{\"core_idea\":\"Retrieving the page title and URL is like reading the label and address on a package to confirm it’s the right one before opening it.\",\"analogy\":\"Imagine you order a book online. When the delivery arrives, you check the label (page title) and the address (URL) on the package to make sure it’s the book you ordered and it came to your house. Similarly, in testing, you check the page title and URL to confirm the browser shows the correct page.\",\"visual\":\"┌─────────────────────────────┐\\n│ Browser Window │\\n│ ┌───────────────────────┐ │\\n│ │ Page Title (Tab Text) │ │\\n│ └───────────────────────┘ │\\n│ ┌───────────────────────┐ │\\n│ │ URL (Address Bar) │ │\\n│ └───────────────────────┘ │\\n│ ┌───────────────────────┐ │\\n│ │ Web Page Content │ │\\n│ └───────────────────────┘ │\\n└─────────────────────────────┘\"},\"build_up\":[{\"level\":\"foundation\",\"title\":\"Understanding Page Title and URL\",\"concept\":\"Learn what page title and URL mean in a web browser context.\",\"content\":\"The page title is the text shown on the browser tab. It usually describes the page content. The URL is the web address shown in the browser's address bar. Both help identify the page you are viewing.\",\"result\":\"You can recognize the page title and URL visually in any browser.\",\"insight\":\"Knowing what the page title and URL represent helps you understand why verifying them matters in testing.\"},{\"level\":\"foundation\",\"title\":\"Setting Up Selenium WebDriver\",\"concept\":\"Prepare the Selenium WebDriver to open a browser and load a web page.\",\"content\":\"Install Selenium Java bindings and a browser driver (like ChromeDriver). Write code to create a WebDriver instance and open a URL using driver.get(\\\"https://example.com\\\").\",\"result\":\"A browser window opens and loads the specified web page.\",\"insight\":\"Setting up WebDriver is essential before you can retrieve page title or URL.\"},{\"level\":\"intermediate\",\"title\":\"Retrieving Page Title in Selenium Java\",\"self_check\":\"Before reading on: do you think driver.getTitle() returns the page title as a String or an object? Commit to your answer.\",\"concept\":\"Use the getTitle() method of WebDriver to get the current page title as a String.\",\"content\":\"Example:\\nString title = driver.getTitle();\\nSystem.out.println(\\\"Page title is: \\\" + title);\",\"result\":\"The console prints the exact title text of the current page.\",\"insight\":\"Understanding that getTitle() returns a simple String lets you easily compare it with expected titles in tests.\"},{\"level\":\"intermediate\",\"title\":\"Retrieving Current URL in Selenium Java\",\"self_check\":\"Before reading on: do you think driver.getCurrentUrl() returns the URL before or after any redirects? Commit to your answer.\",\"concept\":\"Use the getCurrentUrl() method of WebDriver to get the current page URL as a String after all navigation and redirects.\",\"content\":\"Example:\\nString url = driver.getCurrentUrl();\\nSystem.out.println(\\\"Current URL is: \\\" + url);\",\"result\":\"The console prints the full URL of the page currently loaded in the browser.\",\"insight\":\"Knowing getCurrentUrl() reflects the final URL after redirects helps you verify navigation correctness.\"},{\"level\":\"intermediate\",\"title\":\"Using Assertions to Verify Title and URL\",\"self_check\":\"Before reading on: do you think assertions stop the test immediately on failure or continue running? Commit to your answer.\",\"concept\":\"Use assertions to check if the retrieved title and URL match expected values, causing test failure if they don't.\",\"content\":\"Example with JUnit:\\nimport static org.junit.jupiter.api.Assertions.*;\\n\\nString expectedTitle = \\\"Example Domain\\\";\\nassertEquals(expectedTitle, driver.getTitle());\\n\\nString expectedUrl = \\\"https://example.com/\\\";\\nassertEquals(expectedUrl, driver.getCurrentUrl());\",\"result\":\"Test passes if title and URL match; fails with error if not.\",\"insight\":\"Assertions provide automated checks that confirm the page is correct, preventing silent errors.\"},{\"level\":\"advanced\",\"title\":\"Handling Dynamic Titles and URLs\",\"self_check\":\"Before reading on: do you think exact string matching always works for titles and URLs on dynamic sites? Commit to your answer.\",\"concept\":\"Learn strategies to handle pages where titles or URLs change dynamically, like using contains() or regex matching.\",\"content\":\"Example:\\nString title = driver.getTitle();\\nassertTrue(title.contains(\\\"Welcome\\\"));\\n\\nString url = driver.getCurrentUrl();\\nassertTrue(url.matches(\\\"https://example.com/page/\\\\d+\\\"));\",\"result\":\"Tests pass if title or URL partially match expected patterns, allowing flexibility.\",\"insight\":\"Knowing how to handle dynamic values prevents flaky tests that fail due to small expected changes.\"},{\"level\":\"expert\",\"title\":\"Avoiding Common Pitfalls in Title and URL Checks\",\"self_check\":\"Before reading on: do you think checking title and URL alone guarantees the page loaded fully and correctly? Commit to your answer.\",\"concept\":\"Understand the limitations of title and URL checks and learn to combine them with other validations like element presence or page state.\",\"content\":\"Example:\\n// Title and URL check\\nassertEquals(\\\"Home\\\", driver.getTitle());\\nassertEquals(\\\"https://example.com/home\\\", driver.getCurrentUrl());\\n\\n// Additional check\\nassertTrue(driver.findElement(By.id(\\\"main-content\\\")).isDisplayed());\",\"result\":\"Tests become more reliable by verifying page content along with title and URL.\",\"insight\":\"Knowing that title and URL are necessary but not sufficient checks helps build robust tests.\"}],\"under_the_hood\":{\"mechanism\":\"When Selenium WebDriver calls getTitle() or getCurrentUrl(), it communicates with the browser through the WebDriver protocol. The browser returns the current page's title or URL from its internal state. These values reflect the page loaded in the active tab, updated after navigation or redirects. The driver does not parse the page itself but relies on the browser's rendering engine to provide accurate information.\",\"why_designed_this_way\":\"This design separates test code from browser internals, allowing WebDriver to work with many browsers uniformly. Returning simple strings for title and URL keeps the API easy to use and efficient. Alternatives like parsing page source would be slower and more complex. The WebDriver protocol standardizes these commands for cross-browser compatibility.\",\"diagram\":\"┌───────────────┐ ┌───────────────┐ ┌───────────────┐\\n│ Selenium Test │──────▶│ WebDriver API │──────▶│ Browser │\\n│ (Java) │ │ (Commands) │ │ (Rendering) │\\n└───────────────┘ └───────────────┘ └───────────────┘\\n │ │ │\\n │ getTitle() │ │\\n │--------------------▶│ │\\n │ │ get title string │\\n │ │--------------------▶│\\n │ │ │\\n │ │◀--------------------│\\n │◀---------------------│ │\\n │ returns title string │ │\"},\"misconceptions\":[{\"self_check\":\"Quick: Does driver.getTitle() always return the page title immediately after driver.get()? Commit yes or no.\",\"belief\":\"driver.getTitle() instantly returns the correct page title right after calling driver.get(url).\",\"reality\":\"If the page is still loading or redirecting, getTitle() may return an old or empty title. You often need to wait for the page to load fully before retrieving the title.\",\"why_it_matters\":\"Without waiting, tests may fail or pass incorrectly, causing flaky or unreliable results.\"},{\"self_check\":\"Quick: Does driver.getCurrentUrl() return the URL you initially requested or the final URL after redirects? Commit your answer.\",\"belief\":\"driver.getCurrentUrl() always returns the URL passed to driver.get(), ignoring redirects.\",\"reality\":\"driver.getCurrentUrl() returns the actual URL loaded in the browser after all redirects and navigation.\",\"why_it_matters\":\"Tests that expect the original URL may fail if redirects occur, leading to false negatives.\"},{\"self_check\":\"Quick: Is checking only the page title enough to confirm the page loaded correctly? Commit yes or no.\",\"belief\":\"If the page title is correct, the page has loaded fully and correctly.\",\"reality\":\"The title can be correct even if page content is missing or broken. Additional checks are needed for full validation.\",\"why_it_matters\":\"Relying solely on title can miss critical page errors, causing bugs to slip through.\"},{\"self_check\":\"Quick: Does getTitle() return the visible text on the page or the title tag content? Commit your answer.\",\"belief\":\"getTitle() returns any visible text on the page.\",\"reality\":\"getTitle() returns only the content of the \u003ctitle\u003e tag in the HTML head, not visible page text.\",\"why_it_matters\":\"Confusing these can lead to wrong assertions and test failures.\"}],\"expert_zone\":{\"nuances\":[\"Some websites dynamically change the page title after loading using JavaScript, so getTitle() may change during the test session.\",\"In multi-tab or multi-window tests, getTitle() and getCurrentUrl() always refer to the active window; switching windows is necessary to get info from others.\",\"Browser security policies can affect URL retrieval, especially with redirects or cross-origin navigation, causing unexpected URL values.\"],\"when_not_to_use\":\"Relying only on page title and URL is insufficient for complex pages with dynamic content or single-page applications. Instead, use element presence checks, JavaScript execution results, or network monitoring for deeper validation.\",\"production_patterns\":\"In real-world tests, title and URL checks are combined with waits for page readiness and element visibility. Tests often use partial matches or regex for titles/URLs to handle dynamic parts. Also, these checks are part of navigation validation steps in end-to-end test suites.\"},\"connections\":[{\"to_concept\":\"Assertions in Automated Testing\",\"relationship\":\"Builds-on\",\"insight\":\"Understanding how to retrieve page title and URL enables meaningful assertions that confirm navigation success in tests.\"},{\"to_concept\":\"WebDriver Waits and Synchronization\",\"relationship\":\"Builds-on\",\"insight\":\"Knowing that title and URL may not be immediately available teaches the importance of waits to avoid flaky tests.\"},{\"to_concept\":\"Package Labeling and Delivery Verification (Logistics)\",\"relationship\":\"Analogy-based cross-domain\",\"insight\":\"Just like checking a package label and address ensures correct delivery, verifying page title and URL ensures correct page navigation in testing.\"}],\"pitfalls\":[{\"mistake\":\"Checking page title immediately after navigation without waiting.\",\"incorrect_approach\":\"driver.get(\\\"https://example.com\\\");\\nString title = driver.getTitle();\\nassertEquals(\\\"Example Domain\\\", title);\",\"correct_approach\":\"driver.get(\\\"https://example.com\\\");\\nnew WebDriverWait(driver, Duration.ofSeconds(10))\\n .until(ExpectedConditions.titleIs(\\\"Example Domain\\\"));\\nString title = driver.getTitle();\\nassertEquals(\\\"Example Domain\\\", title);\",\"root_cause\":\"The test tries to get the title before the page finishes loading, causing flaky failures.\"},{\"mistake\":\"Using exact string match for URLs that include dynamic query parameters.\",\"incorrect_approach\":\"assertEquals(\\\"https://example.com/page?session=123\\\", driver.getCurrentUrl());\",\"correct_approach\":\"assertTrue(driver.getCurrentUrl().startsWith(\\\"https://example.com/page\\\"));\",\"root_cause\":\"Dynamic parts of the URL cause exact matches to fail unnecessarily.\"},{\"mistake\":\"Assuming getTitle() returns visible page content.\",\"incorrect_approach\":\"String title = driver.getTitle();\\nassertTrue(title.contains(\\\"Welcome Message\\\")); // expecting visible text\",\"correct_approach\":\"String pageText = driver.findElement(By.tagName(\\\"body\\\")).getText();\\nassertTrue(pageText.contains(\\\"Welcome Message\\\"));\",\"root_cause\":\"Confusing the page title with visible page text leads to wrong assertions.\"}],\"key_takeaways\":[\"Page title and URL retrieval are fundamental checks to confirm correct page navigation in automated web tests.\",\"Selenium WebDriver provides simple methods getTitle() and getCurrentUrl() that return strings representing the current page's title and URL.\",\"Always wait for the page to load fully before retrieving title or URL to avoid flaky tests.\",\"Use assertions to compare retrieved title and URL with expected values, but handle dynamic content flexibly.\",\"Title and URL checks alone are not enough; combine them with other validations for robust test coverage.\"],\"metadata\":{\"version\":\"1.0\",\"content_type\":\"testing\",\"estimated_time_minutes\":15,\"depth_level\":\"comprehensive\",\"difficulty_ceiling\":\"expert\"}}},\"subject\":\"selenium_java\",\"title\":\"Page title and URL retrieval\"},\"syllabusData\":{\"part\":\"part-1\",\"subject\":\"selenium_java\",\"difficulty\":\"beginner\",\"metadata\":{\"total_topics\":6,\"total_patterns\":49,\"patterns_with_content\":49,\"created_at\":\"2026-03-03T15:53:02.212926Z\",\"version\":\"4.2\",\"upload_tool\":\"upload_to_mongo.py v2.0\"},\"part_title\":\"Foundations\",\"subjectTitle\":\"Selenium Java\",\"topics\":[{\"topic_id\":\"selenium_java_p1_t1\",\"title\":\"Selenium Java Basics and Setup\",\"order\":1,\"pattern_count\":7,\"patterns\":[{\"pattern_id\":\"selenium_java_why_selenium_with_java_is_an_industry_standard\",\"title\":\"Why Selenium with Java is an industry standard\",\"order\":1,\"has_content\":true},{\"pattern_id\":\"selenium_java_java_environment_setup_jdk_ide\",\"title\":\"Java environment setup (JDK, IDE)\",\"order\":2,\"has_content\":true},{\"pattern_id\":\"selenium_java_maven_project_creation\",\"title\":\"Maven project creation\",\"order\":3,\"has_content\":true},{\"pattern_id\":\"selenium_java_selenium_dependency_configuration\",\"title\":\"Selenium dependency configuration\",\"order\":4,\"has_content\":true},{\"pattern_id\":\"selenium_java_webdriver_setup_chromedriver\",\"title\":\"WebDriver setup (ChromeDriver)\",\"order\":5,\"has_content\":true},{\"pattern_id\":\"selenium_java_webdrivermanager_for_automatic_driver_management\",\"title\":\"WebDriverManager for automatic driver management\",\"order\":6,\"has_content\":true},{\"pattern_id\":\"selenium_java_first_selenium_java_test\",\"title\":\"First Selenium Java test\",\"order\":7,\"has_content\":true}]},{\"topic_id\":\"selenium_java_p1_t2\",\"title\":\"Browser Navigation\",\"order\":2,\"pattern_count\":6,\"patterns\":[{\"pattern_id\":\"selenium_java_why_browser_control_drives_test_flow\",\"title\":\"Why browser control drives test flow\",\"order\":1,\"has_content\":true},{\"pattern_id\":\"selenium_java_opening_urls_driverget\",\"title\":\"Opening URLs (driver.get)\",\"order\":2,\"has_content\":true},{\"pattern_id\":\"selenium_java_page_title_and_url_retrieval\",\"title\":\"Page title and URL retrieval\",\"order\":3,\"has_content\":true},{\"pattern_id\":\"selenium_java_navigation_back_forward_refresh\",\"title\":\"Navigation (back, forward, refresh)\",\"order\":4,\"has_content\":true},{\"pattern_id\":\"selenium_java_window_management_maximize_size\",\"title\":\"Window management (maximize, size)\",\"order\":5,\"has_content\":true},{\"pattern_id\":\"selenium_java_closing_browser_close_vs_quit\",\"title\":\"Closing browser (close vs quit)\",\"order\":6,\"has_content\":true}]},{\"topic_id\":\"selenium_java_p1_t3\",\"title\":\"Locating Elements\",\"order\":3,\"pattern_count\":10,\"patterns\":[{\"pattern_id\":\"selenium_java_why_reliable_element_location_ensures_stability\",\"title\":\"Why reliable element location ensures stability\",\"order\":1,\"has_content\":true},{\"pattern_id\":\"selenium_java_findelement_by_id\",\"title\":\"findElement by ID\",\"order\":2,\"has_content\":true},{\"pattern_id\":\"selenium_java_findelement_by_name\",\"title\":\"findElement by name\",\"order\":3,\"has_content\":true},{\"pattern_id\":\"selenium_java_findelement_by_classname\",\"title\":\"findElement by className\",\"order\":4,\"has_content\":true},{\"pattern_id\":\"selenium_java_findelement_by_tagname\",\"title\":\"findElement by tagName\",\"order\":5,\"has_content\":true},{\"pattern_id\":\"selenium_java_findelement_by_linktext\",\"title\":\"findElement by linkText\",\"order\":6,\"has_content\":true},{\"pattern_id\":\"selenium_java_findelement_by_partiallinktext\",\"title\":\"findElement by partialLinkText\",\"order\":7,\"has_content\":true},{\"pattern_id\":\"selenium_java_findelement_by_cssselector\",\"title\":\"findElement by cssSelector\",\"order\":8,\"has_content\":true},{\"pattern_id\":\"selenium_java_findelement_by_xpath\",\"title\":\"findElement by xpath\",\"order\":9,\"has_content\":true},{\"pattern_id\":\"selenium_java_findelements_for_multiple_matches\",\"title\":\"findElements for multiple matches\",\"order\":10,\"has_content\":true}]},{\"topic_id\":\"selenium_java_p1_t4\",\"title\":\"XPath and CSS Selectors\",\"order\":4,\"pattern_count\":9,\"patterns\":[{\"pattern_id\":\"selenium_java_why_selector_mastery_prevents_fragile_tests\",\"title\":\"Why selector mastery prevents fragile tests\",\"order\":1,\"has_content\":true},{\"pattern_id\":\"selenium_java_absolute_vs_relative_xpath\",\"title\":\"Absolute vs relative XPath\",\"order\":2,\"has_content\":true},{\"pattern_id\":\"selenium_java_xpath_with_attributes\",\"title\":\"XPath with attributes\",\"order\":3,\"has_content\":true},{\"pattern_id\":\"selenium_java_xpath_with_text\",\"title\":\"XPath with text()\",\"order\":4,\"has_content\":true},{\"pattern_id\":\"selenium_java_xpath_axes_parent_followingsibling_preceding\",\"title\":\"XPath axes (parent, following-sibling, preceding)\",\"order\":5,\"has_content\":true},{\"pattern_id\":\"selenium_java_xpath_functions_contains_startswith\",\"title\":\"XPath functions (contains, starts-with)\",\"order\":6,\"has_content\":true},{\"pattern_id\":\"selenium_java_css_selector_syntax\",\"title\":\"CSS selector syntax\",\"order\":7,\"has_content\":true},{\"pattern_id\":\"selenium_java_css_attribute_and_pseudoclass_selectors\",\"title\":\"CSS attribute and pseudo-class selectors\",\"order\":8,\"has_content\":true},{\"pattern_id\":\"selenium_java_choosing_xpath_vs_css_strategy\",\"title\":\"Choosing XPath vs CSS strategy\",\"order\":9,\"has_content\":true}]},{\"topic_id\":\"selenium_java_p1_t5\",\"title\":\"Element Interactions\",\"order\":5,\"pattern_count\":9,\"patterns\":[{\"pattern_id\":\"selenium_java_why_interaction_methods_simulate_user_behavior\",\"title\":\"Why interaction methods simulate user behavior\",\"order\":1,\"has_content\":true},{\"pattern_id\":\"selenium_java_click_actions\",\"title\":\"Click actions\",\"order\":2,\"has_content\":true},{\"pattern_id\":\"selenium_java_typing_text_sendkeys\",\"title\":\"Typing text (sendKeys)\",\"order\":3,\"has_content\":true},{\"pattern_id\":\"selenium_java_clearing_fields\",\"title\":\"Clearing fields\",\"order\":4,\"has_content\":true},{\"pattern_id\":\"selenium_java_submitting_forms\",\"title\":\"Submitting forms\",\"order\":5,\"has_content\":true},{\"pattern_id\":\"selenium_java_getting_text_and_attributes\",\"title\":\"Getting text and attributes\",\"order\":6,\"has_content\":true},{\"pattern_id\":\"selenium_java_checking_state_isdisplayed_isenabled_isselected\",\"title\":\"Checking state (isDisplayed, isEnabled, isSelected)\",\"order\":7,\"has_content\":true},{\"pattern_id\":\"selenium_java_element_dimensions_and_location\",\"title\":\"Element dimensions and location\",\"order\":8,\"has_content\":true},{\"pattern_id\":\"selenium_java_element_screenshots\",\"title\":\"Element screenshots\",\"order\":9,\"has_content\":true}]},{\"topic_id\":\"selenium_java_p1_t6\",\"title\":\"Waits and Synchronization\",\"order\":6,\"pattern_count\":8,\"patterns\":[{\"pattern_id\":\"selenium_java_why_synchronization_eliminates_timing_failures\",\"title\":\"Why synchronization eliminates timing failures\",\"order\":1,\"has_content\":true},{\"pattern_id\":\"selenium_java_implicit_wait\",\"title\":\"Implicit wait\",\"order\":2,\"has_content\":true},{\"pattern_id\":\"selenium_java_explicit_wait_webdriverwait\",\"title\":\"Explicit wait (WebDriverWait)\",\"order\":3,\"has_content\":true},{\"pattern_id\":\"selenium_java_expectedconditions_class\",\"title\":\"ExpectedConditions class\",\"order\":4,\"has_content\":true},{\"pattern_id\":\"selenium_java_fluentwait_with_polling\",\"title\":\"FluentWait with polling\",\"order\":5,\"has_content\":true},{\"pattern_id\":\"selenium_java_custom_expectedcondition\",\"title\":\"Custom ExpectedCondition\",\"order\":6,\"has_content\":true},{\"pattern_id\":\"selenium_java_threadsleep_vs_proper_waits\",\"title\":\"Thread.sleep vs proper waits\",\"order\":7,\"has_content\":true},{\"pattern_id\":\"selenium_java_handling_staleelementreferenceexception\",\"title\":\"Handling StaleElementReferenceException\",\"order\":8,\"has_content\":true}]}]},\"modeCode\":\"DLM\",\"productId\":\"codefly\"}]]\n"])</script><script>self.__next_f.push([1,"13:[[\"$\",\"meta\",\"0\",{\"name\":\"viewport\",\"content\":\"width=device-width, initial-scale=1\"}],[\"$\",\"meta\",\"1\",{\"charSet\":\"utf-8\"}],[\"$\",\"title\",\"2\",{\"children\":\"Page title and URL retrieval in Selenium Java - Deep Dive: Internals \u0026 How It Works | Leyaa.ai\"}],[\"$\",\"meta\",\"3\",{\"name\":\"description\",\"content\":\"Go deep on Page title and URL retrieval in Selenium Java. Internals, mental models, under-the-hood mechanics, misconceptions, common pitfalls, and production patterns. For serious learners.\"}],[\"$\",\"meta\",\"4\",{\"name\":\"author\",\"content\":\"Leyaa.ai\"}],[\"$\",\"link\",\"5\",{\"rel\":\"manifest\",\"href\":\"/manifest.json\",\"crossOrigin\":\"use-credentials\"}],[\"$\",\"meta\",\"6\",{\"name\":\"keywords\",\"content\":\"learning intelligence,AI learning,personalized learning,adaptive learning,study guide,exam preparation,learning platform,education technology,edtech,smart learning\"}],[\"$\",\"meta\",\"7\",{\"name\":\"creator\",\"content\":\"Leyaa.ai\"}],[\"$\",\"meta\",\"8\",{\"name\":\"publisher\",\"content\":\"Leyaa.ai\"}],[\"$\",\"meta\",\"9\",{\"name\":\"robots\",\"content\":\"index, follow\"}],[\"$\",\"meta\",\"10\",{\"name\":\"googlebot\",\"content\":\"index, follow, max-image-preview:large, max-snippet:-1\"}],[\"$\",\"meta\",\"11\",{\"name\":\"content-language\",\"content\":\"en\"}],[\"$\",\"link\",\"12\",{\"rel\":\"canonical\",\"href\":\"https://leyaa.ai/codefly/learn/selenium-java/part-1/selenium-java-page-title-and-url-retrieval/deep\"}],[\"$\",\"link\",\"13\",{\"rel\":\"alternate\",\"hrefLang\":\"en\",\"href\":\"https://leyaa.ai/codefly/learn/selenium-java/part-1/selenium-java-page-title-and-url-retrieval/deep\"}],[\"$\",\"link\",\"14\",{\"rel\":\"alternate\",\"hrefLang\":\"x-default\",\"href\":\"https://leyaa.ai/codefly/learn/selenium-java/part-1/selenium-java-page-title-and-url-retrieval/deep\"}],[\"$\",\"meta\",\"15\",{\"property\":\"og:title\",\"content\":\"Page title and URL retrieval in Selenium Java - Deep Dive: Internals \u0026 How It Works | Leyaa.ai\"}],[\"$\",\"meta\",\"16\",{\"property\":\"og:description\",\"content\":\"Go deep on Page title and URL retrieval in Selenium Java. Internals, mental models, under-the-hood mechanics, misconceptions, common pitfalls, and production patterns. For serious learners.\"}],[\"$\",\"meta\",\"17\",{\"property\":\"og:url\",\"content\":\"https://leyaa.ai/codefly/learn/selenium-java/part-1/selenium-java-page-title-and-url-retrieval/deep\"}],[\"$\",\"meta\",\"18\",{\"property\":\"og:locale\",\"content\":\"en_US\"}],[\"$\",\"meta\",\"19\",{\"property\":\"og:image\",\"content\":\"https://leyaa.ai/Assets/metaImages/leyaa-preview-image.png\"}],[\"$\",\"meta\",\"20\",{\"property\":\"og:image:width\",\"content\":\"1200\"}],[\"$\",\"meta\",\"21\",{\"property\":\"og:image:height\",\"content\":\"630\"}],[\"$\",\"meta\",\"22\",{\"property\":\"og:image:alt\",\"content\":\"Page title and URL retrieval in Selenium Java - Deep Dive: Internals \u0026 How It Works\"}],[\"$\",\"meta\",\"23\",{\"property\":\"og:type\",\"content\":\"article\"}],[\"$\",\"meta\",\"24\",{\"name\":\"twitter:card\",\"content\":\"summary_large_image\"}],[\"$\",\"meta\",\"25\",{\"name\":\"twitter:site\",\"content\":\"@leyaaai\"}],[\"$\",\"meta\",\"26\",{\"name\":\"twitter:creator\",\"content\":\"@leyaaai\"}],[\"$\",\"meta\",\"27\",{\"name\":\"twitter:title\",\"content\":\"Page title and URL retrieval in Selenium Java - Deep Dive: Internals \u0026 How It Works | Leyaa.ai\"}],[\"$\",\"meta\",\"28\",{\"name\":\"twitter:description\",\"content\":\"Go deep on Page title and URL retrieval in Selenium Java. Internals, mental models, under-the-hood mechanics, misconceptions, common pitfalls, and production patterns. For serious learners.\"}],[\"$\",\"meta\",\"29\",{\"name\":\"twitter:image\",\"content\":\"https://leyaa.ai/Assets/metaImages/leyaa-preview-image.png\"}],[\"$\",\"link\",\"30\",{\"rel\":\"icon\",\"href\":\"/leyaa-logo.png\"}],[\"$\",\"link\",\"31\",{\"rel\":\"apple-touch-icon\",\"href\":\"/leyaa-logo.png\"}],[\"$\",\"meta\",\"32\",{\"name\":\"next-size-adjust\"}]]\n"])</script><script>self.__next_f.push([1,"6:null\n"])</script></body></html>