Site icon Letzdotesting

Top 40 Selenium WebDriver Interview Questions & Answers

Top 40 Selenium WebDriver Interview Questions & Answers

1. What is Selenium WebDriver?

2. What are the platforms supported by Selenium Webdriver?

3. What are the different browsers supported by Selenium Webdriver

Note: Headless browser is a web browser without Graphical User Interface, so one cannot see the test execution on screen. 

4. What are the different programming languages supported by Selenium Webdriver?

5. Name any 3 limitations of Selenium WebDriver.

6. What are the different types of locators in Selenium?

Locators are used to identify web elements within the webpage. There are 8 different types of locators in Selenium.

7. What is the command used to launch a browser?

WebDriver driver = new ChromeDriver(); // launch Chrome browser

WebDriver driver = new SafariDriver(); // launch Safari browser

WebDriver driver = new InternetExplorerDriver(); // launch IE browser

WebDriver driver = new FirefoxDriver(); // launch Firefox browser

WebDriver driver = new OperaDriver(); // launch Opera browser

WebDriver driver = new HtmlUnitDriver(); // launch headless browser

8. What is the command to launch an URL?

driver.get("www.letzdotesting.com");

9. What is the command used to get the current page URL?

driver.getCurrentUrl();

10. What is the command to get the webpage title?

driver.getTitle();

11. What is the command to type values in a textbox?

driver.findElement(By.id("username")).sendKeys("Letzdotesting");

12. What is the command to get the text values ?

driver.findElement(By.id("username")).getText();

13. What is the command to clear values in a textbox?

driver.findElement(By.id("username")).clear();

14. What is the command to click a control?

driver.findElement(By.id("loginBtn")).click();

15. What is the command to maximize a browser window?

driver.manage().window().maximize();

Note: Selenium does not have any built-in function for minimizing the browser window! 

16. What is the command to click on a hyperlink?

driver.findElement(By.linkText("Defect tool")).click();

driver.findElement(By.partialLinkText("Defect to")).click();

17. What is the command to find if an element is displayed on a screen?

driver.findElement(By.id("loginBtn")).isDisplayed();

18. What is the command to verify if a checkbox/radio is selected?

driver.findElement(By.id("tool_jira")).isSelected();

19. What is the command to verify if a button is enabled?

driver.findElement(By.id("loginBtn")).isEnabled();

20. What is the command to verify if a particular text is present on the webpage?

driver.getPageSource().contains("Letzdotesting");

21. What are the different commands used for a dropdown list?

selectByValue

Select value = new Select(driver.findElement(By.id("marital_status")));

value.selectByValue("Single");

selectByIndex

Select index = new Select(driver.findElement(By.id("marital_status")));

index.selectByIndex(3);

selectByVisibleText

Select text = new Select(driver.findElement(By.id("marital_status")));

text.selectByVisibleText("Single");

deselectByValue

Select value = new Select(driver.findElement(By.id("marital_status")));

value.deselectByValue("Single");

deselectByIndex

Select index = new Select(driver.findElement(By.id("marital_status")));

index.deselectByIndex(3);

deselectByVisibleText

Select text = new Select(driver.findElement(By.id("marital_status")));

text.deselectByVisibleText("Single");

deselectAll

Select text = new Select(driver.findElement(By.id("marital_status")));

text.deselectAll();

22. Name any 4 commonly used Assertions in Selenium?

23. What are the different navigation commands?

driver.navigate().back(); // Takes you one page backward based on browser's history

driver.navigate().forward(); // Takes you one page forward based on browser's history

driver.navigate().refresh(); // Refresh your current page

driver.navigate().to("www.letzdotesting.com"); // Takes you to new webpage

Note: driver.navigate().to(“www.letzdotesting.com”) and driver.get(“www.letzdotesting.com”) does the same thing! Both are same!!

24. What is the command to right click?

WebElement loginBtn = driver.findElement(By.id("loginBtn"));

Actions rightClick = new Actions(driver); // Actions Class is used

rightClick.contextClick(loginBtn); // contextClick is the method

25. What is the command to mouse hover?

WebElement loginBtn = driver.findElement(By.id("loginBtn"));

Actions move = new Actions(driver); // Actions Class is used

move.moveToElement(loginBtn); // moveToElement is the method

26. What is the command to double-click?

WebElement loginBtn = driver.findElement(By.id("loginBtn"));

Actions doubleClk = new Actions(driver); // Actions Class is used

doubleClk.doubleClick(loginBtn); // doubleClick is the method

27. What is the command used to scroll down to a web element?

WebElement loginBtn = driver.findElement(By.id("loginBtn"));

JavascriptExecutor js = (JavascriptExecutor) driver;

js.executeScript("arguments[0].scrollIntoView();", loginBtn);

28. What is the command to drag and drop?

WebElement sourceTarget = driver.findElement(By.id("loginBtn"));

WebElement destinationTarget = driver.findElement(By.id("submitbtn"));

Actions drgDrp = new Actions(driver); // Actions Class is used

drgDrp.dragAndDrop(sourceTarget, destinationTarget); // dragAndDrop is the method

29. What is the command used to get the attribute values of an element?

driver.findElement(By.id("loginBtn")).getAttribute("value");

30. What is the command used to get the CSS properties of a web element?

driver.findElement(By.id("loginBtn")).getCssValue("color"); 

driver.findElement(By.id("loginBtn")).getCssValue("font-size");

driver.findElement(By.id("loginBtn")).getCssValue("background-color");

driver.findElement(By.id("loginBtn")).getCssValue("height");

driver.findElement(By.id("loginBtn")).getCssValue("width");

driver.findElement(By.id("loginBtn")).getCssValue("font-family");

31. How to handle alert pop-ups?

driver.switchTo().alert().accept(); // To click OK option or to accept the alert pop-up

driver.switchTo().alert().dismiss(); // To click Cancel option or to dismiss the alert pop-up

driver.switchTo().alert().getText(); // To get the alert pop-up text message

driver.switchTo().alert().sendKeys("Hello"); // To type values in the alert textbox

32. What is the difference between findElement() and findElements()?

Note: findElements() will not throw an exception if an element is not found. It just returns the list size as zero, whereas findElement() will throw element not found exception. 

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

34. What are the two types of waits available in Selenium Webdriver?

WebDriver driver = new FirefoxDriver();

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // waits for 10 seconds irrespectively before actions

driver.get("www.letzdotesting.com");

WebElement search = driver.findElement(By.id("searchTextbox"));
WebDriverWait wait = new WebDriverWait(driver, 20); // wait for 20 seconds until the element becomes clickable

WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("loginBtn")));

35. How to handle iFrames?

driver.switchTo().frame(3); // Based on index

driver.switchTo().frame("myframe"); // Based on name or ID

driver.switchTo().frame(WebElement); // Based on WebElement

driver.switchTo().parentFrame(); // Switching to parent frame

driver.switchTo().defaultContent(); // switching to the main frame

36. Name any two testing frameworks that can be integrated with Selenium Webdriver?

37. Name any two build management tools that can be integrated with Selenium Webdriver?

38. What software do you need to run Selenium Webdriver in JAVA?

39. Name any advanced framework design that can be used with Selenium Webdriver?

40. Name any 5 Exceptions that you got while working with Selenium Webdriver.

Thanks for reading 🙂 All the Best!

Suggested Readings : Top 30 Cucumber Interview Questions & Answers

Know anyone who is preparing for Selenium Interview?  Help your friends by sharing this article on Facebook, Twitter, or Google Plus.

Exit mobile version