Selenium WebDriver Latest Job Interview Questions With Answers Part-3

Part 3

11 : Can you tell me the syntax to open/launch Firefox browser In WebDriver software testing tool?
Answer : We can open new Mozilla Firefox browser Instance using bellow given syntax In WebDriver software testing tool.

System.setProperty("webdriver.gecko.driver", "D:\\Selenium Files\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();

12 : What Is XPath and what Is use of It In WebDriver?
Answer : In Selenium WebDriver software testing tool, XPath is used to locate the elements. Using XPath, We can navigate through elements and attributes In an XML document to locate software webpage elements like buttons, text box, links, Images etc..

13 : Which tool you are using to find the XPath of any element?
Answer : I am using Mozilla Firefox AddOns FireBug and FirePath to find the XPath of software web elements. see THIS POST to download it.


14 : What is the difference between absolute XPath and relative XPath?
Answer :

Absolute XPath : Absolute XPath Is the full path starting from root node and ends with desired descendant element's node. It will start using single forward slash(/) as bellow.
Example Of Absolute XPath

Above XPath Is absolute XPath of calc result box given on THIS PAGE. It starts top node html and ends with input node.

Relative XPath : Instead of starting from root node, Relative XPath starts from any In between node or current element's node(last node of element). It will start using double forward slash(//) as bellow.
Example Of Relative XPath

Above XPath Is relative XPath of same calc result box given on THIS PAGE.

15 : How To Handle Dynamic Changing IDs In XPath. 
Example : //div[@id='post-body-3647323225296998740']/div[1]/form[1]/input[1]
In this XPath "3647323225296998740" Is changing every time when reloading the page. How to handle this situation?

Answer : There are many different alternatives In such case.

Alternative 1 : Look for any other attribute which Is not changing every time In that div node like name, class etc. So If this div node has class attribute then we can write xpath as bellow.
//div[@class='post-body entry-content']/div[1]/form[1]/input[1]

Alternative 2 : You can use absolute xpath(full xpath) where you not need to give any attribute names In xpath.

Alternative 3 : Use starts-with function. In this xpath's ID attribute, "post-body-" part remain same every time. So you can use xpath as bellow.

Alternative 4 : Use contains function. Same way you can use contains function as bellow.


  1. I think for 15th Question, Alternative 1 doesnt work, because the class has spaces in it which is called as compound class. Please correct me if I am wrong.