0
0
Selenium Javatesting~5 mins

Page title and URL retrieval in Selenium Java - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What method in Selenium WebDriver retrieves the current page title?
The getTitle() method retrieves the title of the current page loaded in the browser.
Click to reveal answer
beginner
How do you get the current URL of the page in Selenium WebDriver?
Use the getCurrentUrl() method to get the URL of the page currently loaded in the browser.
Click to reveal answer
beginner
Why is it useful to retrieve the page title and URL during testing?
Retrieving the page title and URL helps verify that the browser navigated to the correct page and that the page loaded as expected.
Click to reveal answer
beginner
Example code snippet to print page title and URL using Selenium WebDriver in Java?
String title = driver.getTitle(); String url = driver.getCurrentUrl(); System.out.println("Title: " + title); System.out.println("URL: " + url);
Click to reveal answer
intermediate
What will getTitle() return if the page has no title?
It will return an empty string "" if the page does not have a title element.
Click to reveal answer
Which Selenium WebDriver method returns the current page's URL?
AgetCurrentUrl()
BgetPageUrl()
CgetUrl()
DgetPageTitle()
What does getTitle() return if the page has a title?
AThe page's URL
BThe page's title as a string
CA WebElement
DAn integer
Why would you check the page title in a test?
ATo find broken links
BTo check the browser version
CTo verify the page loaded correctly
DTo get the page source
Which Java code correctly prints the current page URL using Selenium WebDriver?
ASystem.out.println(driver.getCurrentUrl());
BSystem.out.println(driver.getUrl());
CSystem.out.println(driver.getPageUrl());
DSystem.out.println(driver.getTitle());
If a page has no title, what does getTitle() return?
Anull
BThrows an exception
CThe URL instead
DAn empty string ""
Explain how to retrieve and verify the page title and URL using Selenium WebDriver in Java.
Think about methods to get title and URL and how to check them in tests.
You got /4 concepts.
    Describe why checking the page title and URL is important in automated web testing.
    Consider what these checks tell you about the web page state.
    You got /4 concepts.