How to get a specific ID from URL in php webdriver selenium?

I was wondering how I would get a specific ID from an URL. ( If something like this is possible )

For example:

 // You are here: http://test.be/certificate/create
 // Saving new certificate 
 $search11 = $this->webDriver->findElement(WebDriverBy::id('certificate_save'));
 $search11->click();

 // You are here: http://test.be/certificate/11/basicinfo
 // Here I need to get the ID so I can go to the next page

 // You are here: http://test.be/certificate/11/holders

Basically I need the number after the /certificate/ Any suggestions? If something isn't clear feel free to ask.

Thanks in advance

Kind regards

Answers


You can get the url from the Driver object and extract the id from that, something like this:

string url = Driver.Url;
string[] parts = url.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
int id = int.Parse(parts[3]);

EDIT: Sorry just seen you are using php, my code was in c#, the same logic can be used for php as well

$url = $driver->getCurrentURL();
$parts = explode('/', $url);
$id = $parts[4];

Need Your Help

Collision when bounds of a view are changing

ios objective-c uikit-dynamics

I am working with UIDynamicAnimator, UICollisionBehavior and several moving UIImageView.

OpenAuth .Net Claims Request is always null

.net openid dotnetopenauth

I've been using DoNetOpenAuth library and followed the example here