- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Getting the URL of the current page using Selenium WebDriver.
We can obtain the URL of the current page with Selenium webdriver. This is achieved with the help of getCurrentUrl() method. It fetches the URL of the opened application. This method accepts no parameters and strings the URL in the form of String.
Syntax −
String strUrl = driver.getCurrentUrl();
Example
Code Implementation.
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class CurrentUrl{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "https://www.tutorialspoint.com/index.htm"; driver.get(url); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); // get current URL and print String strUrl = driver.getCurrentUrl(); System.out.println("Current Url is:"+ strUrl); driver.quit(); } }
Output
- Related Articles
- How to obtain the page title using Selenium webdriver?
- How do I get current URL in Selenium Webdriver 2 Python?
- Get page title with Selenium WebDriver using Java.
- How to check URL for 404 using Selenium WebDriver?
- How to navigate back to current page from Frame in selenium webdriver?
- How to scroll down the page till page end in the Selenium WebDriver?
- How to set Page Load Timeout using C# using Selenium WebDriver?
- How to know the exact time to load a page using Selenium WebDriver?
- How to scroll the Page up or down in Selenium WebDriver using java?
- How to capture the screenshot of a specific element rather than entire page using Selenium Webdriver?
- How to get the title and URL of the page in Selenium with python?
- How can I scroll a web page using selenium webdriver in python?
- How to scroll a Web Page using coordinates of a WebElement in Selenium WebDriver?
- The Architecture of Selenium WebDriver.
- Wait until page is loaded with Selenium WebDriver for Python.

Advertisements