Selenium Interview Questions Part-1

Selenium Interview questions mostly asked in MNC’s

1.What is difference between Absolute and Relative Xpath ?
Absolute Xpath:
    It always starts with “/”  and starts selection of element from root/start of Page. And it is not recommended due to dependency of Page Layout

Relative Xpath:
    It alway starts with “//” and starts selection from element which is having some unique property. And It recommended to use over Absolute xpath and CSS since it is not depended on page  layout & selection can be done in both direction(Parent node to child node & Child node to Parent )

2.How to find all available links on Web Page ?
Links are having comman tagname as “a”. Hence below method can be used ,
driver.findElements(By.tagname(“a”)) or driver.findElements(By.xpath(“//a”))

3.How to switch to iframe ,alert and window ?
1.For switching to Alert
2.For switching to Iframe
3.For switching to Window

4.What are different ways of switching to iframe ?
Before are three ways to switch to iframe
    1.driver.switchTo().frame(index of iframe)
    2.driver.switchTo().frame(“id or name of iframe”)

5.In your project where you have used collection. ?
1.For making collection of elements having same property like links
    List<WebElement> allLinks=driver.findElements(By.tagname(“a”))
2.During handling Cookies
    Set<Cookie> allCookie= driver.manage().getCookies();
3.During  handling tabs/windows
    Set<String> allWin=driver.getWindowHandles();
6.What are cssSelector locator syntax ?
1.For Element having id as attribute
2.For Element having name/value/type as attribute
    css=tagname[name/value/type=’value of name/value/type’]
3..For Element having classname as attribute

7.What are ways of scrolling using WebDriver ?
1.For scrolling to particular element
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();", element);
2.For scrolling pixel by pixel
((JavascriptExecutor) driver).executeScript(“window.scrollBy(x-pixels,y-pixels)”);
3.For scrolling at bottom of page
((JavascriptExecutor) driver).executeScript("window.scrollBy(0, document.body.scrollHeight)");

8.Give methods used to verify status(checked or not) of check box & element is displayed and clickable.
For Checking Checkbox is selected “isSelected()” is used.
For Checking Element is displayed “isDisplayed()” is used.
For Checking Element is clickable “isEnabled()” is used.

9.List Annotations of TestNG and Junit 5.
TestNG Annotations:
    1. BeforeSuite
    2. AfterSuite
    3. BeforeTest
    4. AfterTest
    5. BeforeClass
    6. AfterClass
    7. BeforeMethod
    8. AfterMethod
    9. DataProvider
Junit 5(Junit Jupiter) Annotation
    1. BeforeAll
    2. AfterAll
    3. BeforeEach
    4. AfterEach
Junit 4 Annotation

10.Difference between get() and navigate().to().
    1.Accepts only url starting with “http” else it will throws exception
    2.Does not maintains history of browser hence forword and backword is not possible.
    3.Waits till page get loaded
    1.Accepts url in String and URL class type.Below are some possible combination
    • driver.navigate().to(“”)
    • driver.navigate().to(new URL(“”))
    2.Maintains history of browser hence forword and backword is possible.
    3.Does not wait to load page.