Scenario: I open www.google.com, input some keywords and click the search button. now i get to the result page. I want to get the current url of this result page, including the query parameters.
I found a method getBrowserUrl()
here phpunit-selenium on github. Line 410
But this method returned the value which I set in the setUp
function.
public function setUp(){
$this->setBrowser(testConfig::$browserName);
$this->setBrowserUrl('http://www.google.com/');
}
public function testGoogleSearch(){
$this->url('');
//input some keywords
.......
//click search button
.......
//want to get the url of result page
$resultUrl= $this->getBrowserUrl();
echo $resultUrl;
}
I got a string 'http://www.google.com/' instead of the whole url of result page. Please help me,thanks!
Click on the “console” tab. In the console, type “document. URL” command and hit enter. You will give the current URL.
You can get the current url by doing path_info = request. META. get('PATH_INFO') http_host = request.
Get Current URL Command In WebDriver, this method fetches the string representing the Current URL of the current web page. It accepts nothing as parameter and returns a String value.
location='url' which can help you to achieve this. String url = "https://www.google.com"; String script = "window. location = \'"+url+"\'"; System. setProperty("webdriver.
The answer is:
$currentURL = $this->url();
I also asked this question here
Thanks to @jaruzafa
From the source code, I'd say it's getCurrentURL()
https://github.com/facebook/php-webdriver/blob/787e71db74e42cdf13a41d500f75ea43da84bc75/lib/WebDriver.php#L43
You can also use
$url=$this->getLocation();
This is how I'll get the current URL
$resultUrl = $this->getSession()->getDriver()->getCurrentUrl();
echo $resultUrl;
or
$resultUrl = $this->getSession()->getCurrentUrl();
echo $resultUrl;
Both are from Behat - Mink
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With