Selenium Interview Question and Answers Series. Episode- 1

Selenium Interview Q & A

The interview Series consists of set of questions in each episode to make you learn in a time based manner. This post is all about selenium episode-1

 

1) What are the annotations used in TestNG ?

@Test, @BeforeSuite, @AfterSuite, @BeforeTest, @AfterTest,  @BeforeClass, @AfterClass, @BeforeMethod, @AfterMethod.

 

2) What is the use of xpath ?

It is used to find the Web Element in web page.  Very useful in identifying the dynamic web elements.

 

3) What are different types of locators ?

By.id(), By.name(), By.tagName(), By.className(), By.linkText(), By.partialLinkText(), By.xpath, By.cssSelector().

 

4) What is the alternate way to click on login button?

Use submit() method but it can be used only when attribute type=submit.

 

5) How do you verify if the check-box/radio is checked or not ?

Using isSelected() method.


driver.findElement(By.xpath("xpath of the checkbox/radio button")).isSelected();</pre><pre>If the return value of this method is true 

then it is checked else it is not.<strong> </strong>

 

 

6) How do you handle alert pop-up ?

To handle alert pop-ups, we need to 1st switch control to alert pop-ups then click on ok or cancle then move control back to main page.

String mainPage = driver.getWindowHandle();

Alert alt = driver.switchTo().alert(); // to move control to alert popup
alt.accept(); // to click on ok.
alt.dismiss(); // to click on cancel.
//Then move the control back to main web page-
driver.switchTo().window(mainPage); → to switch back to main page.

 

 

7) How do you launch IE/chrome browser?

Before launching IE or Chrome browser we need to set the System property.


//To open IE browser

System.setProperty(“webdriver.ie.driver”,”path of the iedriver.exe file ”);

WebDriver driver = new InternetExplorerDriver();

//To open IE browser

System.setProperty(“webdriver.ie.driver”,”path of the iedriver.exe file ”);

WebDriver driver = new InternetExplorerDriver();

 

8) How to perform right click using WebDriver?

Use Actions class

</pre>
Actions act = new Actions(driver); // where driver is WebDriver type
act.moveToElement(webElement).perform();
act.contextClick().perform();
<pre>


9) How do perform drag and drop using WebDriver?

Use Action class

</pre>
Actions act = new Actions(driver);

WebElement source = driver.findElement(By.xpath(“ -----”)); //source ele which you want to drag

WebElement target = driver.findElement(By.xpath(“ -----”)); //target where you want to drop

act.dragAndDrop(source,target).perform();
<pre>


10) Give the example for method overload in WebDriver.

frame(string), frame(int), frame(WebElement).

 

11) How do you upload a file?

To upload a file we can use sendKeys() method.

driver.findElement(By.xpath(“input field”)).sendKeys(“path of the file to upload”);

 

12) How do you click on a menu item in a drop down menu?

selectByValue() or selectByIndex() or selectByVisibleText(). These are the methods of the Select class.

 

13) How do you simulate browser back and forward ?

driver.navigate().back();

driver.navigate().forward();

 

14) How do you get the current page URL ?

driver.getCurrentUrl();

 

15) What is the difference between ‘/’ and ‘//’ ?

// is used to search in the entire structure.

/ it is used to identify the immediate child.

 

16) What is the difference between findElement and findElements?

findElement() – it used to find the one web element. It return only one WebElement type.

findElements()- it used to find more than one web element. It return List of WebElements.


17) How to get typed text from a textbox ?

</pre>
Using getAttribute(“value”) method by passing arg as value.

String typedText = driver.findElement(By.xpath("xpath of box")).getAttribute("value"));

<strong> </strong>
<pre>

18) What are the different exceptions you got when working with WebDriver ?


ElementNotVisibleException, ElementNotSelectableException, NoAlertPresentException, NoSuchAttributeException, NoSuchWindowException, TimeoutException, WebDriverException.


19) How do you clear the contents of a textbox in selenium ?

Using clear() method.

driver.findElement(By.xpath(“xpath of box”)).clear();


20) How do you achieve synchronization in WebDriver ?

Using implicit wait.

driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);

To be continued…

  • Malathi Shetty

    When will more sets of questions available?