Selenium and Xpath

In this Selenium test, can you explain what this call to By.XPath is doing exactly?

string referenceLink = browser.FindElement(By.XPath("/html/body/div[@class='container body-content']/div[@class='page-wrap']/div[@class='container']/div[@class='box-container jumbotron border']/div[@class='row'][1]/div[@class='col-sm-12 col-md-6 col-lg-3'][1]/a[@class='thumbnail text-center']")).GetAttribute("href").Remove(0, 8);
newbiewebSr. Software EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill TorchiaQuality AssuranceCommented:
It looks like this part :

  • /html/body/div[@class='container body-content']/div[@class='page-wrap']/div[@class='container']/div[@class='box-container jumbotron border']/div[@class='row'][1]/div[@class='col-sm-12 col-md-6 col-lg-3'][1]/a[@class='thumbnail text-center']

is starting at the top of the DOM, and then digging down to find a thumbnail.

This part:

  • .GetAttribute("href").Remove(0, 8);

is getting the href of the image element , then removing the first 8 chars of it.


Is the call not working for you any more?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
newbiewebSr. Software EngineerAuthor Commented:
I am just trying to understand it fully, that's all.

What does the By.XPath() do?
Bill TorchiaQuality AssuranceCommented:
In Selenium there are "By" objects. They are used a lot to find elements on the page. Basically they tell Selenium to go look for an element at a location, using a specific method. Docs are here : https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/By.html
newbiewebSr. Software EngineerAuthor Commented:
thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
unit testing

From novice to tech pro — start learning today.