Where should I store XPath variables - in a class or in an external file? What are the (dis)advantages of these approaches?

  • How is this question related to software testing? There is no mention of any tool or methodology or even any terminology related to testing. Only the tags say selenium and automation-testing. Feb 23, 2016 at 2:54

3 Answers 3


I am only working with Page Objects which makes it pretty straightforward to keep them inside the page object where it is used, meaning inside a class.

Actually this way you are accomplishing some things that are important for successful automation projects:

  1. DRY principle (only this one class contains and cares about your xpath)

  2. Ease of use (no loading/transformation of external data necessary)

  3. Readability (other/new programmers/testers will find the necessary info at one place, this keeps complexity in check)

  • it makes sense. I have only a couple of variables which are not Page Objects, like base url, admin credentials and etc. But I still have some variables which are not either Page Objects, nor environment vars, for example path to IE or Chrome driver (I plan to have it variable in my ant and allow user to pick up which browser to use) or mobile device ID which depends on whatever device attached to the computer.
    – Sofiya
    Sep 8, 2015 at 16:57

Usually I keep them in my code specially during the implementation and before SUT is stable. Also when it is in the code, you have more control who/how can access and modify them.
On the other hand, keeping them in a separate file can help in:

  • Updating them easier
  • Having separate XPath files for different environments and switching between them based on some build/deploy parameters.

There is no right answer. Try it both ways (in separate tests) and see which way works better for you.

  • This should be a comment!!! Feb 23, 2016 at 2:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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