I have a URL I am attempting to verify through my test, basically I click on the image of a product and it takes me to the item description page. At the end URL string for this items description page, there is an added (addthis.com) string for social media purposes. My question is how can I assert the URL if it changes browser to browser and session to session?

URL ending

url + "/shop/en-US/products/berry-blue#.VXCXwEb0_-s"

Code Call

Assert.AreEqual(url + "/shop/en-US/products/berry-blue#.VXCXwEb0_-s", driver.Url);

The string at the end "VXCXwEb0" is what is changed dynamically. Is there anyway to assert this URL while ignoring these characters?

2 Answers 2


The Uri class has a property called PathAndQuery that will strip off the fragment identifier (the part after the #).

Assert.AreEqual("/shop/en-US/products/berry-blue", new Uri(driver.Url).PathAndQuery);

If you need to test the host name too, you will need to add that back.


I would use a String.split command. The way it works is that you can split a string into an Array at a certain marker. So in this case for example.

Split using the period and you would have three strings in an array

  1. /shop/en-US/products/berry-blue#
  2. VXCXwEb0_-s", driver
  3. Url

Then you can split the 2nd in the list above on the _ character in a new array which would give you the following

  1. VXCXwEb0
  2. -s", driver

You could also do it in reverse order first on the _ then a period on the first string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.