Selenium with Python Interview Questions and Answers

Selenium with Python Interview Questions and Answers

Last updated on 24th Oct 2020, Blog, Interview Question

About author

Ramkumar (Sr Software Testing Manager )

He is a Proficient Technical Expert for Respective Industry Domain & Serving 8+ Years. Also, Dedicated to Imparts the Informative Knowledge's to Freshers. He Share's this Blogs for us.

(5.0) | 11132 Ratings 2051

In case you’re searching for Selenium with Python Interview Questions and Answers for Experienced or Freshers, you are at the correct place. There is parcel of chances from many presumed organizations on the planet. The Selenium with Python advertise is relied upon to develop to more than $5 billion by 2020, from just $180 million, as per Selenium with Python industry gauges. In this way, despite everything you have the chance to push forward in your vocation in Selenium with Python Development.ACTE offers Advanced Selenium with Python Interview Questions and Answers that assist you in splitting your Selenium with Python interview and procure dream vocation as Selenium with Python Developer.

1.What Is Python?

Ans:

Python is a programming language with objects, modules, threads, exceptions and automatic memory management. 

2.How Python Can Be Used In Software Testing?

Ans:

  • To generate test data; parse test results; generate reports; testing API calls etc.
  • Python to extract requirements from a Word document.
  • For testing tasks automation, setting up environments for tests, extracting performance data, etc…
  • Testers use Python extensively in many companies with Selenium for test automation.
  • For writing desktop applications used by testers.
  • Test data manipulation.
  • To build test environment
  • Testing with IronPython on .NET

3.What Python Frameworks Do You Know?

Ans:

Framework called Web2py, PAMIE (Python automation Module for I. E.), The pytest framework

4.What Tools That Helps Python Development Do You Know?

Ans:

There are good tools for helping Python development such as Notepad++ with the PyNPP plugin and Eclipse with PyDev and PyUnit

5.What Is A “Unittest” In Python?

Ans:

The unit testing framework of Python is known as “unittest”.  It supports the sharing of setups, automation testing, shutdown code for tests, aggregation of tests into collections, among others.

6.How Python Is Interpreted?

Ans:

Python language is an interpreted language. The Python program runs directly from the source code. It converts the source code that is written by the programmer into an intermediate language, which is again translated into machine language that has to be executed.

7.What Is The Difference Between “xrange” And “range”?

Ans:

“Xrange” returns the “Xrange” object while range returns the “list” irrespective of the size of the “range”.

8.Define “module” And “package”?

Ans:

  • Each Python program file is a “module”, which imports other modules like “objects” and “attributes”.
  • A Python program folder is a “package” of “modules”.  A package can have “modules” or “subfolders”.

9.Why is my pip not working when my python is not installed properly?

Ans:

The executable path is not set properly.

Subscribe For Free Demo
[contact-form-7 404 "Not Found"]

10.What are the commands for downloading selenium?

Ans:

  • pip install –U selenium
  • sudo pip install python

11.How can we know that our python is properly installed or not?

Ans:

  • pip –version

12.How can we implement unit test framework in our scripts?

Ans:

By using:- import unittest

13.What are the different locators used?

Ans:

    1. 1.Tag name
    2. 2.Class name
    3. 3.id
    4. 4.link text
    5. 5.Partial link text
    6. 6.CSS Selector
    7. 7.XPath
    8. 8.Name

14.Which is the slowest locator?

Ans:

Xpath.

15.Which is the best locator?

Ans:

The selection of the best locator depends on the web elements or the ui page we are automating.

16.What is the library to be imported to add keyboard actions to our scripts?

Ans:

from selenium.webdriver.common.keys import Keys

17.What is the library to be imported to add mouse actions to our scripts?

Ans:

from selenium.webdriver.common.actionchains import ActionChains

18.What is Selenium?

Ans:

It’s a Automation toolkit

19.What is a locator?

Ans:

It’s an element in web page with which the python script would interact through the selenium driver

20.What is a Webdriver?

Ans:

Selenium provides a tool to interact with the different web browsers. And they control the operation of the script. Ex: chromedriver, Iedriver, gecko for firefox.

21.What’s XPATH?

Ans:

It is the extensible markup language’s pathfinder where the data is stored in XML format like Key value pair

22.What’s the difference between / and // in xpath?

Ans:

  • / : absolute path // relative path

23.What’s the explicit and implicit wait?

Ans:

  • Explicit wait makes the browser wait for a given duration or the condition is true else, it will throw a time exceeded exception.
  • Implicit wait- will make the browser wait for a defined time and the execution continues.

24.What are window handles?

Ans:

Selenium with Python Interview Questions and Answers During the script execution if there is a new window that pops up then they have an address and they have a handle, each handle is listed in the variable handles[]

Ex: To reference those windows driver.switch_window(browser.window(handle[0]))

25.What are alerts and how do you handle it?

Ans:

Alerts are the popup windows that you get when there is notification to the user,

Handling them: alert_var = browser.switch_to_alert()

To dismiss: alert_var.dismiss()

To accept: alert_var.accept() etc

Get Selenium with Python 100% Practical Training

26.How to find elements by hyperlink?

Ans:

  • Find_element_by_link_text(“text of that hyperlink”).click()

27.How do you write the text in the login form?

Ans:

  • Find_element_by_id(“username_field”).send_keys(“USERNAME”)

28.What is the difference between close() and quit() func of the browser?

Ans:

Browser.close() will close the current executing window and you can always switch to other window handles even after closing currently active one.Browser.quit() – will close the complete browser with all the open windows, this func handle and makes sure the processes are closed and terminated correctly without any memory leaks.

29.When the webpage is dynamic, which element locator do we use to locate an element?

Ans:

  • driver.findElementByXpath()

30.How do we define a function in Python ?

Ans:

def functionName: Function body

31.What is an indentation in python?

Ans:

Python does not use braces to indicate the start & stop of function. It uses indentation (Whitespaces) to make the compiler understand the start & stop of function.

32.What is the syntax for “for” loop if we have to run for loop for 3 times?

Ans:

for 1 in 5:Print(“)

33.What is WebDriver in selenium?

Ans:

WebDriver is a plugin that helps to run selenium test scripts on a web browser.

34.What is the WebDriver used to run selenium script on chrome browser?

Ans:

chrome driver

35.What type of languages can we use to write selenium scripts?

Ans:

  • We can use any scripting language.
  • Get Selenium with Python Online Training

36.Can I use selenium for automation scripting without selenium IDE?

Ans:

Yes, selenium can be imported as a module in any other programming platform & write selenium test scripts.

Course Curriculum

Learn Selenium With Python Certification Course to Enhance Your Career

Weekday / Weekend BatchesSee Batch Details

37.What is the use of automation testing?

Ans:

It will reduce manpower & it also reduces the time that we spend on doing Selenium with Python every time.

38.Can we do data-driven testing using selenium?

Ans:

Yes, bypassing values as parameters during run time.

39.Is selenium helpful for standalone application testing?

Ans:

No, Selenium is only used as a test automation tool for web driver applications.

40.Why do you prefer to use Python for Selenium?

Ans:

Python is not very large or complicated and one of the easy-to-use programming languages. Python APIs permit us to connect to the browser through Selenium. Selenium can convey normal Python commands to various browsers, in spite of the disparities in browser design.

41.What versions are there of Selenium?

Ans:

  • Selenium WebDriver – Used for the automation of tests in web applications.
  • Selenium IDE – Firefox plugin to record and run tests.
  • Selenium Grid – Allows you to run Selenium tests in parallel through multiple machines.

42.What programming languages does Selenium Webdriver support?

Ans:

Languages supported are: Java, C #, PHP, Ruby, Python.

43.What kind of tests can we perform with Selenium Webdriver?

Ans:

We can perform functional and regression tests on web applications.

44.What are the limitations of Selenium?

Ans:

The main limitations of selenium are:

  • You can only perform tests in web applications, not for desktop or mobile. (But other tools are available to automate desktop application GUI tests.)
  • Captcha and barcode reading cannot be automated with Selenium. Selenium with Python is needed for them.
  • The user who is going to perform automatic tests with Selenium Python must have previous knowledge of Python.

45.What are the different types of locators that we can use to search for an element with Selenium?

Ans:

The locators that we can use with Selenium are ID, Name, ClassName, TagName, LinkText, and Partial LinkText, XPath, CSS Selector.

46.What is an XPath?

Ans:

Xpath (XML Path Language) is a language that allows you to retrieve information from an XML document by defining a syntax to set parts in an XML document, allowing you to navigate through its elements and attributes, as well as allowing basic manipulation of Booleans, numbers, and strings.

47.What is the difference between / and // in an XPath expression?

Ans:

We will use / to start the selection from a node in the document. It allows us to create absolute Xpath expressions. We will use // to start the selection from anywhere in the document. It allows us to create relative Xpath expressions.

48.What are the different types of drivers currently supported by Selenium Webdriver?

Ans:

The supported drivers are Gecko driver (new from Selenium 3 to create an instance of FirefoxDriver), ChromeDriver, InternetExplorerDriver, SafariDriver, OperaDriver, AndroidDriver, IPhoneDriver, and HtmlUnitDriver.

49.How can we select an option of a dropdown using Selenium Webdriver?

Ans:

To be able to select the value of a dropdown using Selenium Webdriver we have to use the Select class of Webdriver. Through this class we can select a value of a dropdown by its value, its visible text or its index number (position).

50.What is Selenium WebDriver

Ans:

Selenium Web driver is a set of classes which automate the web application.

51.Is Selenium Web Driver Automation Tool?

Ans:

No Selenium web Driver is not an Automation tool, it’s a framework or set of classes which is used to automate a web based application.

52.What kind of application best suited for Selenium and why it should be selected.

Ans:

It is used to automate web based applications and have browser and Platform compatibility. It supports multiple language such as java, C# and Python

Course Curriculum

Get On-Demand Selenium With Python Training with Industry Concepts By IT Experts

  • Instructor-led Sessions
  • Real-life Case Studies
  • Assignments
Explore Curriculum

53.Can Selenium Web Services be tested using Selenium?

Ans:

No it is used to automate only web based applications.

54.How Can we launch Different browsers using python?

Ans:

For Chrome

  • driver=Webdriver.Chrome(“PathofChromedriver”)

For Firefox

  • driver=webdriver.Firefox(“Path of Firefox Driver”)

For IE

  • driver=webdriver.Ie(“Path of IE Driver”)

55.How Synchronization works in Selenium.

Ans:

Synchronization is achieved using Implicit Wait and Explicit Wait.

56.What is Implicit Wait.

Ans:

Implicit Wait is used to default waiting time.

57.What is explicit Wait.

Ans:

Explicit Wait is used to halt the execution until condition is met or when time is elapsed.

58.How can I enter the values in the textbox using python?

Ans:

  • driver.find_element(By.ID,”Value”).send_keys(“Value”)

59.How can we check if control is enabled or not?

Ans:

  • driver.find_element(By.ID,”Value”).is_enabled()

, this specific method will return if true or false.

60.How can we get the text of a web element.

Ans:

  • driver.find_element(By.ID,”Value”).text

this specific method will return innertext of the control.

61.Is there any other way of retrieving text from a web element.

Ans:

  • driver.find_element(By.ID,”Value”).get_attribute(“InnerText”)

62.What are the different ways of selecting the values in dropdown.

Ans:

  • SelectByValue: select the option based on option value.
  • selectByVisibleText: selects the option based on visible text.
  • selectByIndex: selects the option base on Index

63.what are the different Navigation command in selenium

Ans:

it is used to refresh

  • driver.refresh()

it is used to navigate back

  • driver.back()

it is used to move forward

  • driver.forward()

64.What is the difference b/w findelement and findelements

Ans:

  • FindElement returns the first matching element.
  • FindElements returns more than one element.

65.what is the difference b/w Driver.Close and Driver.quit

Ans:

  • close is used to close the entire browser
  • quit is used to close the working tab.

66.Can selenium handle the windows pop up?

Ans:

No Selenium can’t handle windows pop Up

67.Can selenium handle WebBased Pop Up.

Ans:

Yes it can handle web based pop up using

  • “driver.switch_to_alert()”

68.How can I capture a screenshot in selenium.

Ans:

  • driver.get_screenshot_as_file(“filename”)

with this method we can take a screenshot.

69.What is switch Class in selenium.

Ans:

Switch classes are used to switch between the different browser,frames and alert pop up.

70.What Action class in selenium

Ans:

ACtion class is a user facing API to achieve complex user action events.

71.How can we perform drag drop in selenium

Ans:

act=ActionChains(driver)

  • act.drag_and_drop(sourcelement,targetelement)

with this method we can perform drag and drop

72.How can mice hover on a control in selenium?

Ans:

  • with the above method we mouse hover on element, element argument is web element where we need to mouse hover.

73.Can we move the mouse control to specific coordinate in selenium

Ans:

Yes we can, selenium provides an Action class in which we can make use of the act.move_by_offset() method to move the mouse control to specific coordinates.

74.Write a method to read data from a web table for a specific row and column index using selenium.

Ans:

  • def GetData(rowIndex,colIndex):
  • table rows=driver.find_element_by_id(“IdValue”).find_elements_by_tag_name(“tr”)
  • table Definitions=table rows[rowIndex+1].find_elements_by_tag_name(“td”)
  • return table Definitions[colIndex].get_attribute(“innerText”)

75.What are Python unitTest default methods

Ans:

#Will execute before the execution of each test method

def setUp(self):

pass

# will execute once before it executes any test methods

def setUpClass(cls):

pass

#will execute after the execution of each test method

def tearDown(self):

pass

# will execute after it executes all the test methods.

def tearDownClass(cls):

pass

76.How will install selenium in python

Ans:

We will use PIP command to install selenium

Pip install selenium Version_Nos

Selenium Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download

77.What is passed in python.

Ans:

pass means no operation to be done

78.How can we convert string to int in python.

Ans:

using int(“23″) to convert to int.

str(23) to convert to string

79.How will you handle exception in python

Ans:

try,except and finally keyword is used to handle the exception

try:

#code

except: #catches the exception

finally: #executes the block whether any exception is raised or not.

80.What are the different data types supported in python

Ans:

integer,string,float and complex are the supported data types in python

81.What is MRO in python

Ans:

Method Resolution order is used in inheritance concepts

where class is inheriting multiple classes and in all the parent classes, the same method is defined. Child class is confused which method to call during run time. So the MRO helps to resolve the issue.

82.How will you identify when a web element doesn’t have any of the unique locators?

Ans:

we can make use of the get_attribute method to get a web element from a list of web elements.

for control in controls:

  • if control.get_attribute(“attributename”)==”attributeValue”:

#found the matching control

83.How to execute javascript in selenium with python

Ans:

  • driver.execute_script(script)

above method will execute the javascript.

84.What are the different way entering value TextBox

Ans:

  • find_element_by_id(“val”).send_keys(“valuetoebeentered”)
  • other is using Action Class act=ActionChains (driver)
    send_keys_to_element(control, ”Valuetobeenterd”)

85.What is the use of Xpath

Ans:

xpath is used to find the web element in a webpage.

86.What are the different exception in selenium

Ans:

  • webdriver exception
  • noalertPresent Exception
  • nosuchwindow Exception
  • no such element exception
  • timeoutexception

87.How will perform double click on web element

Ans:

  • act=ActionChains(driver)
  • act.double_click(control)

Above method will be used to double click on the control.

88.How will you handle multiple windows in selenium

Ans:

we can use the “switch_to_window” method to switch between the multiple windows. where in argument we would be sending the address of the window in the form of string.

89.What is the framework?

Ans:

Framework defines a set of rules or best practices which we can follow in a systematic way to achieve the desired results.

90.What are the different automation Frameworks

Ans:

  • Data Driven Framework
  • Key Driven Framework
  • Hybrid Framework

91.write a program for the below pattern with only one while loop

Ans:

  • *
  • **
  • ***
  • ****
  • *****
  • ****
  • ***
  • **
  • *
  • a = 0
  • bool = True
  • While(a<=5):
  • if(a<0): break; if(a==5): bool = False if(bool): a = a + 1 else: a = a – 1 print(“*”*a)

92.What is the difference between Assert and Verify?

Ans:

  • Assert it is used to verify the result. If the test case fails then it will stop the execution of the test case there itself and move the control to another test case.
  • Verify it is also used to verify the result. If the test case fails then it will not stop the execution of that test case.

93.Why should Selenium be selected as a test tool?

Ans:

Selenium is free and open source, has a large user base and helps communities cross Browser compatibility (Firefox, Chrome, Internet Explorer, Safari etc.) have great platform compatibility (Windows, Mac OS, Linux etc.)

supports multiple programming languages (Java, C#, Ruby, Python, Pearl etc.) has fresh and regular repository developments supports distributed testing

94.What are the testing types that can be supported by Selenium?

Ans:

Selenium supports the following types of testing:

  • Functional Testing
  • Regression Testing

95.When should I use Selenium IDE?

Ans:

Selenium IDE is the simplest and easiest of all the tools within the Selenium Package. Its record and playback feature makes it exceptionally easy to learn with minimal acquaintances to any programming language. Selenium IDE is an ideal tool for a naïve user.

96.What is the Java implementation of Python popularly known?

Ans:

Jython.

97.What is used to create unicode strings in Python?

Ans:

Add u before the string u ‘mystring’

98.Explain how python is interpreted.

Ans:

The Python program runs directly from the source code. Each type of Python programs are executed code is required. Python converts source code written by the programmer into intermediate language which is again translated into the native language machine language that is executed. So Python is an Interpreted language.

99.What Are The Benefits Of Using Python?

Ans:

Python is a programming language with objects, modules, threads, exceptions and automatic memory management. The benefits of pythons are that it is simple and easy, portable, extensible, build-in data structure and it is open source.

Are you looking training with Right Jobs?

Contact Us

Popular Courses