0% found this document useful (0 votes)
3 views9 pages

Selenium Interview Question and Answars

The document provides a comprehensive overview of Selenium, including its bug life cycle, various exceptions, locators, and methods for interacting with web elements. It explains the differences between various locator strategies, wait types, and how to handle alerts and multiple windows. Additionally, it covers the use of Action and Switch classes for complex user interactions and the distinctions between assertions in testing.

Uploaded by

hotchat8686
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views9 pages

Selenium Interview Question and Answars

The document provides a comprehensive overview of Selenium, including its bug life cycle, various exceptions, locators, and methods for interacting with web elements. It explains the differences between various locator strategies, wait types, and how to handle alerts and multiple windows. Additionally, it covers the use of Action and Switch classes for complex user interactions and the distinctions between assertions in testing.

Uploaded by

hotchat8686
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

what is bug life cycle?

what are the exceptions in selenium


 ans: NoSuchWindowException.
 NoSuchFrameException.
 NoSuchElementException.
 NoAlertPresentException.
 InvalidSelectorException.
 TimeoutException.
 ElementNotVisibleException.
 ElementNotSelectableException.

1) What are the different locators used?

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

2) Which is the slowest locator?


Xpath.
3) Which is the best locator?
The selection of the best locator depends on the web elements or the ui
page we are automating.
4) What is the library to be imported to add keyboard actions to our
scripts?
from selenium.webdriver.common.keys import Keys
5) What is the library to be imported to add mouse actions to our
scripts?
from selenium.webdriver.common.actionchains import ActionChains

6) What is a locator?
It’s an element in web page with which the python script would interact
through the selenium driver
7) What is a Webdriver?
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.

8) Whats XPATH?
It is the extensible markup language’s path finder where the data is stored
in XML format like Key value pair
9) Whats the difference between / and // in xpath?
/ : absolute path // relative path
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

10) Whats explicit and implicit wait?


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
11) What are window handles?
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[]
12) What are alerts and how do you handle?
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

13) How to find element by hyperlink?


Find_element_by_link_text(“text of that hyperlink”).click()
14) How do you write the text in the login form?
Find_element_by_id(“username_field”).send_keys(“USERNAME”)

15) What is the difference between close() and quit() func of the
browser?
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.
16) When webpage is dynamic which element locater do we use to
locate an element?
driver.findElementByXpath()
17) What is WebDriver in selenium?
WebDriver is a plugin that helps to run selenium test scripts on a web
browser.
18) Can I use selenium for automation scripting without selenium
IDE?
Yes, selenium can be imported as a module in any other programming
platform & write selenium test scripts.

19) Can we do data-driven testing using selenium?


Yes, bypassing values as parameters during run time.
20) What versions are there of Selenium?
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.

21) What are the different types of locators that we can use to search
for an element with Selenium?
The locators that we can use with Selenium are ID, Name, ClassName,
TagName, LinkText, and Partial LinkText, XPath, CSS Selector.

22) What is an XPath?


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.
23) What is the difference between / and // in an XPath expression?
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.
24) How can we select an option of a dropdown using Selenium
Webdriver?
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).
25) How Synchronization works in Selenium.
Synchronization is achieved using Implict Wait and Explicit Wait.

26) What is Implicit Wait.


Implicit Wait is used to default waiting time.
27) What is explicity Wait.
Explicit Wait is used to halt the execution untill condition is met or when
time is elasped.

28) How can enter the values in text box using python.
driver.find_element(By.ID,”Value”).send_keys(“Value”)
29) How can we get text of a web element.
driver.find_element(By.ID,”Value”).text, this specific method will return
innertext of the control.
30) what are the different Navigation command in selenium
it is used to refresh
driver.refresh()
it is used to navigate back
driver.back()
it is used to move forward
driver.forward()
31) What is the difference b/w findelement and findelements

 FindElement returns first matching element.


 FindElements returns more than one element

32) what is the difference b/w Driver.Close and Diver.quit

 close is used to close the entire browser


 quit is used to close the working tab.

33) Can selenium handle WebBased Pop Up.


Yes it can handle webbased pop up using “driver.switch_to_alert()”
34) How can capture screenshot in selenium.
driver.get_screenshot_as_file(“filename”) with this method we can take
screen shot.

35) What are switch Class in selenium.


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

36) What Action class in selenium


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

37) How can we perform drag drop in selenium


act=ActionChains(driver)
act.drag_and_drop(sourcelement,targetelement), with this method we can
perform drag and drop
38) How can mouse hover on a control in selenium.
act=ActionChains(driver)
act.move_to_element(element)
with the above method we mouse hover on element, element argument is
web element where we need to mouse hover
39) How will identify when web element doesn’t have any of the
unique locater.
we can make use of the get_attribute method to get web element from list
of web elements.
for control in controls:
if control.get_attribute(“attributename”)==”attributeValue”:
#found the matching control
40) How to execute java script in selnium with python
driver.execute_script(script)
above method will execute the java script.

41) What are the differnt way entering value TextBox

 find_element_by_id(“val”).send_keys(“valuetoebeentered”)
 other is using Action Class
act=ActionChains(driver)

42) What is the use of Xpath


xpath is used to find the web element in webpage.
43) What are the different exception in selenium

 webdriver exception
 noalertPresent Exception
 nosuchwindow Exception
 nosuchelement exception
 timeoutexception
44) How will perform double click on web element
act=ActionChains(driver)
act.double_click(control)
Above method will be used to double click on the control.
45) How will you handle multiple windows in selenium
we can use “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.

46) What is the difference between Assert and Verify?


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.

47)difference between soft assert hard assert?

Hard Assert:Hard Asserts are used when you want to halt the
execution of the test script (or test method)

when the assert condition does not match with the expected
result.

Soft Assert:oft Asserts are used when the test script (or test
method) need not be halted
when the assertion condition does not meet the
expected result
48) Why XPath is slower than other locators?
Xpath allows bidirectional flow which means the traversal can be both ways
from parent to child and child to parent as well. Css allows only one
directional flow which means the traversal is from parent to child
only. Xpath is slower in terms of performance and speed

You might also like