Skip to main content

Selenium Interview Questions

Displaying 1 - 10 of 152

What are the multiple ways to click on Submit button in Selenium?

Here are the list of techniques:

.click() method: You can use .click() method to click on any button of software web application. Means element's type = "button" or type = "submit", .click() method will works for both.

WebElement myButton = driver.findElement(By.cssSelector("locator"));
myButton.click();

.submit() method: If you will look at firebug view for any form's submit button then always It's type will be "submit". In this case, .submit() method Is very good alternative of .click() method.

WebElement myButton = driver.findElement(By.cssSelector("locator"));
myButton.submit();

Keys.Enter: 

WebElement myButton = driver.findElement(By.cssSelector("locator"));
myButton.sendKeys(Keys.ENTER);

Action Class:

WebElement myButton = driver.findElement(By.cssSelector(locator));
Actions builder = new Actions(driver);
    builder
        .moveToElement(myButton)
        .click()
        .build()
        .perform();

JavaScriptExecutor:

WebElement myButton = driver.findElement(By.cssSelector(locator));
JavascriptExecutor js = (JavascriptExecutor)driver;		
js.executeScript("arguments[0].click();", myButton);

What are the challenges with PageFactory?

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

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?

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?

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?

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?

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);
Subscribe to Selenium Interview Questions

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.