Selenium Interview Questions and Answers

FREE Online Courses: Enroll Now, Thank us Later!

Check the latest and frequently asked Selenium Interview Questions and Answers. These will help you crack your selenium interviews for job. Let’s start!!!

Selenium Interview Questions and Answers

1. How would you open a webpage using Selenium WebDriver?

from selenium import webdriver


driver = webdriver.Chrome()
driver.get("https://www.example.com")

2. How to maximize the browser window in Selenium WebDriver?

driver.maximize_window()

3. How to locate an element by ID using Selenium WebDriver?

element = driver.find_element_by_id("element_id")

4. How to locate an element by name using Selenium WebDriver?

element = driver.find_element_by_name("element_name")

5. How to locate an element by class name using Selenium WebDriver?

element = driver.find_element_by_class_name("class_name")

6. How to locate an element by tag name using Selenium WebDriver?

element = driver.find_element_by_tag_name("tag_name")

7. How to locate an element by CSS selector using Selenium WebDriver?

element = driver.find_element_by_css_selector("css_selector")

8. How to locate an element by XPath using Selenium WebDriver?

element = driver.find_element_by_xpath("xpath_expression")

9. How to click on a button using Selenium WebDriver?

button = driver.find_element_by_id("button_id")
button.click()

10. How to input text into a text box using Selenium WebDriver?

text_box = driver.find_element_by_id("textbox_id")
text_box.send_keys("input text here")

11. How to submit a form using Selenium WebDriver?

form = driver.find_element_by_id("form_id")
form.submit()

12. How to get the text of an element using Selenium WebDriver?

element = driver.find_element_by_id("element_id")
element_text = element.text

13. How to check if an element is displayed using Selenium WebDriver?

element = driver.find_element_by_id("element_id")
element.is_displayed()

14. How to check if an element is enabled using Selenium WebDriver?

element = driver.find_element_by_id("element_id")
element.is_enabled()

15. How to check if an element is selected using Selenium WebDriver?

element = driver.find_element_by_id("element_id")
element.is_selected()

16. How to get the title of a webpage using Selenium WebDriver?

title = driver.title

17. How to get the current URL of a webpage using Selenium WebDriver?

url = driver.current_url

18. How to navigate back to the previous page using Selenium WebDriver?

driver.back()

19. How to refresh a webpage using Selenium WebDriver?

driver.refresh()

20. How to close the browser using Selenium WebDriver?

driver.close()

21. What is wrong with the following code that is intended to open a webpage using Selenium WebDriver in Python?

from selenium import WebDriver

driver = WebDriver()
driver.get("https://www.google.com")

Ans – The correct import statement is from selenium import webdriver (lowercase “w” in “webdriver”), and the correct way to instantiate a WebDriver object is driver = webdriver.Chrome() (where “Chrome” can be replaced with the name of the desired browser driver).

22. What is wrong with the following code that is intended to locate an element by ID using Selenium WebDriver in Python?

element = driver.get_element_by_id("username")

Ans: The correct method name is find_element_by_id() (not get_element_by_id()).

23. What is wrong with the following code that is intended to input text into a text box using Selenium WebDriver in Python?

element = driver.find_element_by_id("username")
element.sendKeys("admin")

Ans: The correct method name is send_keys() (not sendKeys()).

24. What is wrong with the following code that is intended to check if an element is displayed using Selenium WebDriver in Python?

element = driver.find_element_by_id("logo")
element.Displayed()

Ans: The correct method name is is_displayed() (not Displayed()).

25. What is wrong with the following code that is intended to click on a button using Selenium WebDriver in Python?

button = driver.find_element_by_id("login")
button.submit()

Ans: The submit() method is used to submit a form, not to click on a button. The correct method to click on a button is click().

26. What is wrong with the following code that is intended to locate an element by XPath using Selenium WebDriver in Python?

element = driver.findElement(By.xpath("//input[@name='username']"))

Ans: The correct way to call the find_element_by_xpath() method is driver.find_element_by_xpath() (not driver.findElement(By.xpath())).

27. What is wrong with the following code that is intended to check if an element is selected using Selenium WebDriver in Python?

element = driver.find_element_by_id("checkbox")
element.Selected()

Ans: The correct method name is is_selected() (not Selected()).

28. What is wrong with the following code that is intended to maximize the browser window using Selenium WebDriver in Python?

driver.maximizeWindow()

Ans: The correct method name is maximize_window() (lowercase “w” in “window”).

29. What is wrong with the following code that is intended to navigate to the previous page using Selenium WebDriver in Python?

driver.Back()

Ans: The correct method name is back() (lowercase “b”).

30. What is wrong with the following code that is intended to wait for an element to be visible using Selenium WebDriver in Python?

wait = WebDriverWait(driver, 10)
element = wait.until(EC.visibility_of_element_located((By.ID, "username")))

Ans: The necessary imports are missing. The following imports are needed:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

Summary

This was all about the top Selenium Interview Questions and Answers. Hope you enjoyed the article.

Did you like our efforts? If Yes, please give DataFlair 5 Stars on Google

follow dataflair on YouTube

Leave a Reply

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