How to use getCurrentUrl method of org.openqa.selenium.Interface WebDriver class

Best Selenium code snippet using org.openqa.selenium.Interface WebDriver.getCurrentUrl

Source:DriverEventListener.java Github

copy

Full Screen

...40 log.trace("Navigated to {}", url);41 }42 @Override43 public void beforeNavigateBack(WebDriver driver) {44 log.trace("Trying to navigate back for page with URL: {}", driver.getCurrentUrl());45 }46 @Override47 public void afterNavigateBack(WebDriver driver) {48 log.trace("Navigated back for page with URL: {}", driver.getCurrentUrl());49 }50 @Override51 public void beforeNavigateForward(WebDriver driver) {52 log.trace("Trying to navigate forward for page with URL: {}", driver.getCurrentUrl());53 }54 @Override55 public void afterNavigateForward(WebDriver driver) {56 log.trace("Navigated forward for page with URL: {}", driver.getCurrentUrl());57 }58 @Override59 public void beforeNavigateRefresh(WebDriver driver) {60 log.trace("Trying to refresh page with URL: {}", driver.getCurrentUrl());61 }62 @Override63 public void afterNavigateRefresh(WebDriver driver) {64 log.trace("Refreshed page with URL: {}", driver.getCurrentUrl());65 }66 @Override67 public void beforeFindBy(By by, WebElement element, WebDriver driver) {68 log.trace("Trying to find element with locator {}", by.toString());69 }70 @Override71 public void afterFindBy(By by, WebElement element, WebDriver driver) {72 log.trace("Found element with locator {}", by.toString());73 }74 @Override75 public void beforeClickOn(WebElement element, WebDriver driver) {76 log.trace("Trying to click on element with tag name: {}", element.getTagName());77 }78 @Override...

Full Screen

Full Screen

Source:FriendDriver.java Github

copy

Full Screen

...50 /**51 * Start a new session, using the current URL.52 */53 public void newSession() {54 newSession(getWebDriver().getCurrentUrl());55 }5657 /**58 * @return true if an active session exists, else false.59 */60 public boolean hasSession() {61 return getSessionId() != null;62 }6364 /**65 * Start a new session with the given URL.66 *67 * @param url the URL of the page to load.68 */69 public void newSession(final String url) {70 getWebDriver().manage().deleteAllCookies();71 navigateToUrl(url);72 }7374 /**75 * @return the session ID for the driver, or null if no session.76 */77 public String getSessionId() {78 Cookie cookie = getWebDriver().manage().getCookieNamed(SESSION_ID_COOKIE);79 if (cookie == null) {80 return null;81 }82 return cookie.getValue();83 }8485 /**86 * Refresh page.87 */88 public void refreshPage() {89 getWebDriver().navigate().refresh();90 }9192 /**93 * @param url the URL to navigate to94 */95 public void navigateToUrl(final String url) {96 getWebDriver().navigate().to(url);97 }9899 /**100 * @return the Alert or null101 */102 public Alert getAlert() {103 try {104 return getWebDriver().switchTo().alert();105 } catch (Exception e) {106 return null;107 }108 }109110 /**111 * @return the page title112 */113 public String getPageTitle() {114 return getWebDriver().getTitle();115 }116117 /**118 * @return the current URL119 */120 public String getCurrentUrl() {121 return getWebDriver().getCurrentUrl();122 }123124 /**125 * Close the current window.126 */127 public void close() {128 getWebDriver().close();129 }130131 /**132 * Close all windows.133 */134 public void quit() {135 getWebDriver().quit(); ...

Full Screen

Full Screen

Source:_1_00_Browsers.java Github

copy

Full Screen

...39 //check the title of the page40 System.out.println(driver.getTitle());41 42 // to check the current URL of the website43 System.out.println(driver.getCurrentUrl());44 45 // to close the browser46 driver.close(); */47 48 /* ------------------------------------------------------------ 49 //@@2 with Firefox & gecko driver50 System.setProperty("webdriver.gecko.driver", "C:/Users/Gupta2 Sagar/Downloads/Selenium Course Rahul Shetty/Softwares/3. Drivers/geckodriver.exe");51 WebDriver driver = new FirefoxDriver();52 53 driver.get("https://www.rahulshettyacademy.com");54 55 //check the title of the page56 System.out.println(driver.getTitle());57 58 // to check the current URL of the website59 System.out.println(driver.getCurrentUrl());60 61 // to close the browser62 driver.close(); */63 64 /* ---------------------------------------------------------- */65 //@@3 with Mocrosoft Edge & gecko driver66 System.setProperty("webdriver.edge.driver", "C:/Users/Gupta2 Sagar/Downloads/Selenium Course Rahul Shetty/Softwares/3. Drivers/msedgedriver.exe");67 WebDriver driver = new EdgeDriver();68 driver.get("https://www.rahulshettyacademy.com");69 70 System.out.println(driver.getTitle());71 System.out.println(driver.getCurrentUrl());72 73 driver.close();74 75 }76}...

Full Screen

Full Screen

Source:WebdriverTest.java Github

copy

Full Screen

...12import org.openqa.selenium.logging.Logs;13public interface WebdriverTest{14 public interface WebDriver extends SearchContext {15 void get(String var1);16 String getCurrentUrl();17 String getTitle();18 List<WebElement> findElements(By var1);19 WebElement findElement(By var1);20 String getPageSource();21 void close();22 void quit();23 Set<String> getWindowHandles();24 String getWindowHandle();25 org.openqa.selenium.WebDriver.TargetLocator switchTo();26 org.openqa.selenium.WebDriver.Navigation navigate();27 org.openqa.selenium.WebDriver.Options manage();28 @Beta29 public interface Window {30 void setSize(Dimension var1);...

Full Screen

Full Screen

Source:WebDriverImpl.java Github

copy

Full Screen

...36 webDriver.get(s);37 httpGetCounter.increment();38 }39 @Override40 public String getCurrentUrl() {41 return webDriver.getCurrentUrl();42 }43 @Override44 public String getTitle() {45 return webDriver.getTitle();46 }47 @Override48 public <T extends WebElement> List<T> findElements(By by) {49 return webDriver.findElements(by);50 }51 @Override52 public <T extends WebElement> T findElement(By by) {53 return webDriver.findElement(by);54 }55 @Override...

Full Screen

Full Screen

Source:JetFaceBook.java Github

copy

Full Screen

...31 32 //System.out.println(driver.getTitle());33 //SpiceJet - Flight Booking for Domestic and International, Cheap Air Tickets34 35 //System.out.println(driver.getCurrentUrl());36 //https://www.spicejet.com/37 38 //driver.navigate().back();39 40 //driver.quit();41 42 driver.get("https://www.facebook.com/");43 44 driver.findElement(By.name("email")).sendKeys("9444256792");45 46 driver.findElement(By.xpath("//input[@type= 'password']")).sendKeys("1234LAKS");47 48 driver.findElement(By.name("login")).click();49 50 System.out.println(driver.getTitle());51 //Facebook52 53 System.out.println(driver.getCurrentUrl());54 //https://www.facebook.com/55 56 driver.quit();57 58 59 60 61 62 63 64 65 66 }67}...

Full Screen

Full Screen

Source:Pra6.java Github

copy

Full Screen

...6 public static void main(String[] args) {7 System.setProperty("webdriver.gecko.driver", "C:\\Users\\Nikki\\JavaProgarams\\geckodriver.exe");8 WebDriver driver = new FirefoxDriver();9 driver.get("https://gcreddy.com/project/admin/login.php");10 String Url1 = driver.getCurrentUrl();11 driver.findElement(By.linkText("Online Catalog")).click();12 String Url2 = driver.getCurrentUrl();13 if (Url2.equals("http://gcreddy.com/project/")) {14 System.out.println("redirecting functionality from admin to user interface before login - Passed");15 } else {16 System.out.println("redirecting functionality from admin to user interface before login - Failed");17 }18 driver.navigate().back();19 String Url3 = driver.getCurrentUrl();20 driver.findElement(By.name("username")).sendKeys("gcreddy");21 driver.findElement(By.name("password")).sendKeys("Temp@2020");22 driver.findElement(By.id("tdb1")).click();23 String Url4 = driver.getCurrentUrl();24 if (Url1 == Url3) {25 System.out.println("redirecting functionality from admin to user interface After login - Passed");26 } else {27 System.out.println("redirecting functionality from admin to user interface After login - Failed");28 }29 System.out.println(Url1);30 System.out.println(Url2);31 System.out.println(Url3);32 System.out.println(Url4);33 }34}...

Full Screen

Full Screen

Source:launchingBrowser.java Github

copy

Full Screen

...7 //WebDriver driver = new WebDriver(); we can not do that coz WebDriver is an interface and we can not create objects of and interface8 System.setProperty("webdriver.gecko.driver", "Driver/geckodriver.exe");//only windows user should specify .exe, not mac users9 WebDriver driver = new FirefoxDriver();//WebDriver is an interface//ChromeDriver extends RemoteWebDriver10 driver.get("https://www.google.com");// we have to type the address of the website or URL, calling a get method to get to a particular website11 driver.getCurrentUrl(); // this method returns the URL of this web browser12 String url= driver.getCurrentUrl();//returns the current url in the browser13 System.out.println("The current URL loaded in browser is : "+ url);14 driver.getTitle();//this method returns the title of the page15 String title= driver.getTitle();16 System.out.println("The current title of the page is : " +title);17 driver.close();18 }19}...

Full Screen

Full Screen

getCurrentUrl

Using AI Code Generation

copy

Full Screen

1package org.openqa.selenium;2public interface WebDriver {3public abstract void get(String url);4public abstract String getCurrentUrl();5public abstract String getTitle();6public abstract List<WebElement> findElements(By by);7public abstract WebElement findElement(By by);8public abstract String getPageSource();9public abstract void close();10public abstract void quit();11}12package test;13import org.openqa.selenium.WebDriver;14import org.openqa.selenium.firefox.FirefoxDriver;15public class TestGetCurrentUrl {16public static void main(String[] args) {17WebDriver driver = new FirefoxDriver();18String currentUrl = driver.getCurrentUrl();19System.out.println("Current URL is: " + currentUrl);20driver.quit();21}22}

Full Screen

Full Screen

getCurrentUrl

Using AI Code Generation

copy

Full Screen

1package com.example.tests;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.firefox.FirefoxDriver;4public class GetCurrentUrl {5 public static void main(String[] args) {6 WebDriver driver = new FirefoxDriver();7 System.out.println(driver.getCurrentUrl());8 driver.close();9 }10}

Full Screen

Full Screen

getCurrentUrl

Using AI Code Generation

copy

Full Screen

1String currentUrl = driver.getCurrentUrl();2System.out.println("Current URL is: " + currentUrl);3String title = driver.getTitle();4System.out.println("Title of the current page is: " + title);5String pageSource = driver.getPageSource();6System.out.println("Source code of the current page is: " + pageSource);7String windowHandle = driver.getWindowHandle();8System.out.println("Handle of the current window is: " + windowHandle);9Set<String> windowHandles = driver.getWindowHandles();10System.out.println("Handles of all the windows are: " + windowHandles);11driver.close();12driver.quit();

Full Screen

Full Screen

getCurrentUrl

Using AI Code Generation

copy

Full Screen

1package com.example;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.chrome.ChromeDriver;4public class Example {5 public static void main(String[] args) {6 WebDriver driver = new ChromeDriver();7 String url = driver.getCurrentUrl();8 System.out.println(url);9 driver.quit();10 }11}

Full Screen

Full Screen

getCurrentUrl

Using AI Code Generation

copy

Full Screen

1String currentUrl = driver.getCurrentUrl();2System.out.println("Current URL of the page is: " + currentUrl);3System.out.println("Current URL of the page is: " + currentUrl);4System.out.println("Current URL of the page is: " + currentUrl);5System.out.println("Current URL of the page is: " + currentUrl);6System.out.println("Current URL of the page is: " + currentUrl);7System.out.println("Current URL of the page is: " + currentUrl);8System.out.println("Current URL of the page is: " + currentUrl);

Full Screen

Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful