11 : Can you tell me the syntax to open/launch Firefox browser In WebDriver software testing tool?
System.setProperty("webdriver.gecko.driver", "D:\Selenium Files\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
VIEW PRACTICAL example.
12 : What Is XPath and what Is use of It In WebDriver?
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.
/html/body/div[3]/div[2]/div[2]/div[2]/div[2]/div[2]/div[2]/div/div[4]/div[1]/div/div/div/div[1]/div/div/div/div[1]/div[2]/form/table/tbody/tr[1]/td/input
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 :
//input[@id='Resultbox']
Above XPath Is relative XPath of same calc result box given on THIS PAGE.
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.
/html/body/div[3]/div[2]/div[2]/div[2]/div[2]/div[2]/div[2]/div/div[4]/div[1]/div/div/div/div[1]/div/div/div/div[1]/div[2]/div[1]/form[1]/input[1]
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.
//div[starts-with(@id,'post-body-')]/div[1]/form[1]/input[1]
Alternative 4 : Use contains function. Same way you can use contains function as bellow.
div[contains(@id,'post-body-')]/div[1]/form[1]/input[1]
2 thoughts on “Selenium WebDriver Latest Job Interview Questions With Answers Part-3”
Awesome post
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.