Selenium Interview Questions

Displaying 1 - 10 of 142

Why is Selenium a choice tool for automation testing?

07/26/2022 - 17:30 by devraj
  • It is open source
  • It supports distributed testing
  • It has regular repository developments
  • It has a large user base and support community
  • It has wide platform compatibility – Windows, Mac OS, and Linux, etc. 
  • It has cross-browser compatibility – Internet Explorer, Chrome, Firefox, Safari, etc.
  • It supports multiple programming languages – Java, C#, Ruby, Perl, Python, etc.

What are the challenges with PageFactory?

06/01/2022 - 00:58 by devraj

Below are the challenges with PageFactory:

  1. No of Pages: If there is an application with hundreds or thousands of web pages then the time and the effort in the development of automation framework will be high.
  2. Maintenance Overhead: The cost increases when maintenance overhead increases which are due to the maintenance of large class as they break the OO design principle.
  3. Programming Best Practices: The development of POM framework for multiple pages is equal to developers work thus testers should be highly knowledgeable in programming best practices.
  4. Not Generic Model: Page object model is not a generic model and its specific to the applications.

The best approach to overcome the above challenges is by refactoring the POM concept to Screenplay Pattern.

If Timeout of Explicit wait is 30 Seconds and Timeout for Implicit Wait is 60 seconds

05/31/2022 - 03:20 by devraj

Consider element is not found then for how much time script will wait before the exception is thrown. 

Solution:

Case 1: When Implicit Wait > Explicit Wait. For Example Implicit Wait is 60 seconds and Explicit Wait is 30 Seconds.

Then, Script will wait for 60 seconds.

Case 2: When Explicit Wait > Implicit Wait. For Example Implicit Wait is 20 seconds and Explicit Wait is 40 Seconds.

Then, Script will wait for 40 seconds.

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

05/19/2022 - 19:51 by devraj

If that menu has been created by using select tag then we can use the methods selectByValue() or selectByIndex() or selectByVisibleText(). These are the methods of the Select class.

If the menu has not been created by using the select tag then we can simply find the xpath of that element and click on that to select.

How do perform drag and drop using Selenium WebDriver?

05/19/2022 - 19:50 by devraj

Use Action Class:

Actions act = new Actions(driver);
WebElement source = driver.findElement(By.xpath("")); //source element which you want to drag
WebElement target = driver.findElement(By.xpath("")); //target where you want to drop
act.dragAndDrop(source, target).perform();

How do you launch IE/Firefox/Chrome browser using Selenium?

05/19/2022 - 19:47 by devraj

Check below code:

WebDriver driver;

if(browser.equals("Chrome"))
{	
    System.setProperty("webdriver.chrome.driver", Constants.CHROME_EXE);
    driver = new ChromeDriver();
}
else if(browser.equals("Firefox")) 
{
    System.setProperty("webdriver.gecko.driver", Constants.FIREFOX_EXE);
    driver = new FirefoxDriver();
}
else if(browser.equals("IE"))
{
    System.setProperty("webdriver.ie.driver","Constants.IE_EXE");
    driver = new InternetExplorerDriver();
}

How do you handle alert in Selenium?

05/19/2022 - 19:46 by devraj

To handle alert pop-ups, we need to 1st switch control to alert then click on ok or cancel 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);