Retrieve the URL of the current page.

Usage

.getCurrentUrl([callback])

Parameters

Name Type description
callback
Optional
Function

Example

describe('Navigation commands demo', function() {
  test('demoTest', function(browser) {
    // navigate to new url:
    browser.navigateTo('https://nightwatchjs.org');

    // Retrieve to url with callback:
    browser.getCurrentUrl(function(result) {
      console.log(result.value);
    });
  });

  test('demoTestAsync', async function(browser) {
    const currentUrl = await browser.navigateTo('https://nightwatchjs.org').getCurrentUrl();
    console.log('currentUrl:', currentUrl); // will print 'https://nightwatchjs.org'
  });

});

W3C WebDriver spec