Selenium Interview Questions and Answers – Part 2

On this page, you can find Selenium Interview questions and answers which may benefit to freshers to experienced professional. This is part 2 of this interview questions series.

1. How to Handle windows authentication popup using any third party tool .

Below are the steps to achieve this Using Autoit (Third Party Tool) –
Download and in Autoit editor write script through below command
ControlFocus(), ControlSet(), ControlClick()
Save file and Compile Script with your version and after that you get .exe file.
Java code for executing .exe file
Runtime.getRuntime().exec(\\Path)
It throws checked exception IOexception.

2. What are the different types of Exceptions in Selenium Webdriver?

Refer this post for detailed answer

3. What is StaleElementException?

StaleElementException occurs if I find an element, the DOM gets updated then I try to interact with the element.

4. Can we enter text without using sendKeys()?

Yes by using JavascriptExecutor

WebDriver driver = new FirefoxDriver();
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("document.getElementById("textbox_id").value='new value';);

5. How to find more than one web element in the list?

At times, we may come across elements of same type like multiple hyperlinks, images etc arranged in an ordered or unordered list. Thus, it makes absolute sense to deal with such elements by a single piece of code and this can be done using WebElement List.
Sample Code:

// Storing the list
List <WebElement> elementList = driver.findElements(By.xpath("//div[@id='example']//ul//li"));

// Fetching the size of the list 
int listSize = elementList.size(); 
for (int i=0; i<listSize; i++)
{
// Clicking on each service provider link 

serviceProviderLinks.get(i).click();

// Navigating back to the previous page that stores link to service providers 
driver.navigate().back();
}

6. What is the difference between driver.close() and driver.quit command?

close(): WebDriver’s close() method closes the web browser window that the user is currently working on or we can also say the window that is being currently accessed by the WebDriver. The command neither requires any parameter nor does is return any value.
quit(): Unlike close() method, quit() method closes down all the windows that the program has opened.
Same as close() method, the command neither requires any parameter nor does is return any value.

7. Difference between findElement/findElements ?

findElement () will return only single WebElement and if that element is not located or we use some wrong selector then it will throw NoSuchElement exception.
findElements() will return List of WebElements – for this we need to give locator in such a way that it can find multiple elements and will return you list of webelements then using List we can iterate and perform our operation.

import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class findElementDemo {
public static void main(String[] args) throws Exception {
WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://google.com");
Thread.sleep(5000);
List<WebElement> links=driver.findElements(By.xpath(".//*[@id='menu-top']/li")); System.out.println("Total element is "+links.size());
Iterator<WebElement> i1=links.iterator();
while(i1.hasNext)
WebElement ele1=i1.next();
String name=ele1.getText();
System.out.println("Elements name is "+name);
}
}
}

8. Difference between assert and verify in selenium Webdriver

When an “assert” fails, the test will be aborted. Assert is best used when the check value has to pass for the test to be able to continue to run log in.
Where if a “verify” fails, the test will continue executing and logging the failure.Verify is best used to check non critical things. Like the presence of a headline element.

9. How will you execute your login script using chrome browser from your editor using selenium?

System.setProperty("webdriver.chrome.driver","C:\\Users\\Public\\Documents\\Selenium\\chromedriver.exe"); 
WebDriver driver = new ChromeDriver();

10. Can we use multiple catch in try, how ?

Yes, we can use. Refer below Example –

public static void main(String args[]){ try{
int a[]=new int[5];
a[5]=30/0;
}
catch(Exception e)
{
System.out.println("common task completed");
}
 catch(ArithmeticException e) 
{
System.out.println("task1 is completed");
}
 catch(ArrayIndexOutOfBoundsException e)
 {
System.out.println("task 2 completed");
}
 System.out.println("rest of the code...");
}
}

Refer below posts for next interview questions –

Selenium Interview Questions and Answers – Part 2

Selenium Interview Question and Answers – Part 3

Selenium Interview Question and Answers – Part 4

Selenium Interview Question and Answers – Part 5

Leave Comment

Your email address will not be published. Required fields are marked *

Looking for learning Framework Development from Scratch? Lookout for Detailed Framework Development videos on YouTube here -

https://www.youtube.com/automationtalks

Get the Framework code at Github Repo: https://github.com/prakashnarkhede?tab=repositories