0% found this document useful (0 votes)
12 views

Selenium Interview QA-RM01

The document provides a comprehensive overview of various Selenium WebDriver commands and concepts, including methods for interacting with web elements, handling alerts, and managing browser windows. It also discusses frameworks like JUnit and TestNG, along with their annotations and functionalities. Additionally, it covers advanced topics such as handling pop-ups, file uploads, and implementing data-driven and keyword-driven frameworks.

Uploaded by

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

Selenium Interview QA-RM01

The document provides a comprehensive overview of various Selenium WebDriver commands and concepts, including methods for interacting with web elements, handling alerts, and managing browser windows. It also discusses frameworks like JUnit and TestNG, along with their annotations and functionalities. Additionally, it covers advanced topics such as handling pop-ups, file uploads, and implementing data-driven and keyword-driven frameworks.

Uploaded by

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

1) What is the difference between "type" and "typeAndWait"

command?
If you need to type keyboard key values into a text field of the web
application, "type" command will be used. Another reason for its usage is
selecting values of the combo box. "typeAndWait" command is used
when your typing is completed and software web page start reloading.

2) How can the user get a text of a web element?


User can retrieve the text of the specified web element by using get
command. It doesn’t require any parameter but returns a string value.
copy
1. String Text = driver.findElement(By.id(“Some Text”)).getText()
is an example of it.

3) How a text written in a text field could be cleared?


A text written in a text field could be deleted by using the
clear() method.

4) How to check a checkBox in Selenium?


The same click() method could be used for checking checkbox as well as
for clicking buttons or radio buttons.

5) How to verify if the checkbox/radio is checked or not?


isSelected() method is used to verify if the checkbox/radio is checked or
not. An example -
copy
1. driver.findElement(By.xpath("XPath of the checkbox/radio
button")).isSelected();

6) What is the alternate way to click on login button?


submit() method could be used as the alternate way to click on login
button, but only if attribute type=submit.
7) How to select a value in a dropdown?
WebDriver’s Select class is used to select value in the drop down.
copy
1. selectByVisibleText:
2. Select selectByVisibleText = new Select
(driver.findElement(By.id(“id_of_some_element”)));
3. selectByVisibleText.selectByVisibleText(“some_visible_text”);

8) What is the difference between setSpeed() and sleep() methods?


Both of these methods delay the speed of execution. The main difference
between them is setSpeed sets a speed while will apply delay time
before every Selenium operation takes place. thread.sleep() will set up
wait only for once.
For Example:
• sleep(5000)- It will wait for 5 seconds. It is executed only once, where
the command is written.
• setSpeed("5000")- It also will wait for 5 seconds. It runs each
command after setSpeed delay by the number of milliseconds
mentioned in set Speed.

9) What is the difference between findElement () and findElements


()?
Both of them let user to find elements in the current web page matching
to the specified locator value. But if you use findElement(), only the first
matching element would be fetched. An example:

copy
1. WebElement element =
driver.findElements(By.xpath(“//div[@id=’example’]//ul//li”))

If you use findElements(), the all matching elements would be fetched


and stored in the WebElements list. An example:
copy
1. List elementList =
driver.findElements(By.xpath(“//div[@id=’example’]//ul//li”));
10) How can we handle Web-based pop-up?
There are four methods of the effective Web-based pop-up handling:
• string getText() method returns the text displayed on the alert box
• void accept() method clicks on the “Ok” button as soon as the pop-up
window appears
• void dismiss() method clicks on the “Cancel” button as soon as the
pop-up window appears
• void sendKeys(String stringToSend) method enters the specified
string pattern into the alert box

11) Do you know a way to refresh browser by using Selenium?


The list of commands to refresh a page in Selenium:
• navigate().refresh()
• getCurrentUrl()
• navigate().to(driver.getCurrentUrl())
• sendKeys(Keys.F5)

12) How can we maximize browser window in Selenium?


copy
1. driver.manage().window().maximize(); //command is used to maximize
browser window in Selenium

13) How can we find the value of different attributes like name,
class, value of an element?
copy
1. getAttribute("{attributeName}") //method is used find the value of
different attributes of an element

14) Could cookies be deleted in Selenium?


copy
1. driver.manage().deleteAllCookies(); //command is used for deleting all
cookies

15) How to perform right click using Selenium WebDriver?


The next Actions class is used to perform right click:
copy
1. Actions act = new Actions(driver); // where driver is WebDriver type
2. act.moveToElement(webElement).perform();
3. act.contextClick().perform();

16) How do perform drag and drop using Selenium WebDriver?


The next Actions class is used to perform drag and drop:
copy
1. Actions builder = new Actions(driver);
2. Action dragAndDrop = builder.clickAndHold(SourceElement)
3. moveToElement(TargetElement)
4. release(TargetElement)
5. build();
6. dragAndDrop.perform();

17) How to check if an element is visible on the page?


The return method type is logical. If it returns true then element is visible
otherwise it is not. isDisplayed() method could be used for it:
copy
1. driver.findElement(By.id(“id_of_element”)).isDisplayed();

18) How to check if a button is enabled on the page?


isEnabled() method could be used for it:
copy
1. driver.findElement(By.id(“id_of_element”)).isEnabled();

19) What kind of mouse actions can be performed in Selenium?


Selenium supports different mouse actions, such as:
• click(WebElement element)
• contextClick(WebElement element)
• doubleClick(WebElement element)
• mouseUp(WebElement element)
• mouseDown(WebElement element)
• mouseMove(WebElement element)
• mouseMove(WebElement element, long xOffset, long yOffset)
20) Can you write the code to double click an element in Selenium?
Code to double click an element in Selenium:
copy
1. Actions action = new Actions(driver);
2. WebElement element=driver.findElement(By.id("elementId"));
3. action.doubleClick(element).perform();

21) How to mouse hover an element in Selenium?


Code to mouse hover over an element in Selenium:
copy
1. Actions action = new Actions(driver);
2. WebElement element=driver.findElement(By.id("elementId"));
3. action.moveToElement(element).perform();

22) What kind of keyboard operations can be performed in


Selenium?
Selenium lets to perform different kinds of keyboard operations, such as:
• .pressKey("non-text keys") is used for keys like control, function keys
etc that are non-text
• .releaseKey("non-text keys") is used in conjunction with key press
event to simulate releasing a key from keyboard event
• .sendKeys("sequence of characters") is used for passing character
sequence to an input or textbox element.

23) What is JUnit? And what is JUnit Annotation?


JUnit is an open source Java applications testing framework, introduced
by Apache. A process of adding a special form of syntactic metadata to
Java source code is called annotation. JUnit Annotations are: variables,
parameters, packages, methods and classes.

24) What is TestNG and why is it better than JUnit?


TestNG is a testing framework inspired from JUnit and NUnit in a way to
use the merits by both the developers and testers. Here are some new
functionalities that make it more powerful and easier to use, such as:
• test that your code is multithread safe
• support for data-driven testing
• support for parameters
• a variety of tools and plug-ins support (Eclipse, IDEA, Maven, etc...)
• default JDK functions for runtime and logging
• dependent methods for application server testing
• flexible test configuration

25) What kinds of annotations are used in TestNG? The following


kinds of annotations are used in TestNG: • Test
• BeforeSuite
• AfterSuite
• BeforeTest
• AfterTest
• BeforeClass
• AfterClass
• BeforeMethod
• AfterMethod

26) How to set test case priority in TestNG?


TestNG "Priority" is used to schedule the test cases. In order to achieve,
we need to add an annotation as @Test(priority=??). The default value
will be zero for priority. If you don't mention the priority, it will take all
the test cases as "priority=0" and execute.
The example below shows the usage of the priority for test cases.
As we have not defined the priority for test case "Registration", it will get
executed first and then the other test cases based on priority.
copy
1. import org.testng.annotations.Test;
2. public class testNGPriorityExample {
3. @Test
4. public void registerAccount()
5. {
6. System.out.println("Create an account");
7. }
8. @Test(priority=2)
9. public void sendEmail()
10. {
11. System.out.println("Confirm your email");
12. }
13. @Test(priority=1)
14. public void login ()
15. {
16. System.out.println("Execute login after confirmation");
17. }
18. }

copy
1. import org.testng.annotations.Test;
2. public class testNGPriorityExample {
3. @Test
4. public void registerAccount() {
5. System.out.println("Create an account");
6. }
7. @Test(priority=2)
8. public void sendEmail() {
9. System.out.println("Confirm your account");
10. }
11. @Test(priority=1)
12. public void login() {
13. System.out.println("Execute login after confirmation");
14. }
15. }

27) Explain how you can find broken images in a page using
Selenium Web driver?
You have to follow the next steps to find broken images in a page using
Selenium Web driver:
• get XPath and get the all links on the page using the tag name • click
on every link on the page • look for 404/500 in the target page title 55)
Can captcha and bar code reader be automated by using Selenium?
Neither captcha, no bar code reader can be automated by using
Selenium.

28) How to verify tooltip text using Selenium? The tooltip text in
Selenium could be verified by fetching the value of 'title'

• attribute. An example:
• copy 1. String toolTipText = element.getAttribute("title");
29) How to locate a link using its text in Selenium?
linkText() and partialLinkText() are used for link location. The
examples:
copy 1. WebElement link1 =
driver.findElement(By.linkText(“some_link_test”)); 2. WebElement link2 =
driver.findElement(By.partialLinkText(“some_link_part_text”));

30) Can we find all links on a web page? As all links are of anchor tag
'a', so we can find all of them on a web page by locating elements of
tagName ‘a’: copy 1. List links = driver.findElements(By.tagName("a"));
31) How can we capture screenshots in Selenium? We can take the
screenshots in selenium by using getScreenshotAs method of
TakesScreenshot interface: copy 1. File scrFile =
((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); 2.
FileUtils.copyFile(scrFile, new File("C:\\screenshot1.jpg")); 60) Explain
how colors could be handled in Selenium WebDriver? To handle
colors could be handled in Selenium WebDriver by using Use
getCssValue(arg0) function to get the colors by sending ‘color’ string as
an argument. 61) How many exceptions do you know in Selenium
WebDriver? There are 5 different exceptions Selenium WebDriver: •
NoAlertPresentException,
• NoSuchElementException
• NoSuchWindowException
• TimeoutException
• WebDriverException
32) What is selenium grid?

 Selenium grid is hub of selenium servers which are linked with


specific environment and browsers
 We can link diff browsers form diff operating system in to one
single hub and all the selenium test will be obtained to the
selenium grid and grid will divert the traffic to specific
environment
 Selenium will help to run sequential and parallel test across the
diff browsers

33) How will you use Selenium to upload a file?


File uploading action could be performed by using
element.sendKeys("path of file") on the webElement of input tag and
type file: < name="fileUpload" type="file" />

34) What is Robot API?


Robot API is used to control keyboard or mouse to interact with OS
windows like Download pop-up, Alerts, Print Pop-ups, etc. or native
Operation System applications like Notepad, Skype, Calculator, etc.

35) What methods of Robot Class do you know?


Some commonly and popularly used methods of Robot Class during
web automation:
• • keyPress(): method with press down arrow key of Keyboard

Example:
copy
1. keyPress(KeyEvent.VK_DOWN)
• keyRelease(): method with release down arrow key of Keyboard:
Example:
copy
1. robot.keyRelease(KeyEvent.VK_DOWN)
• mouseRelease() method will release the right click of your mouse

Example:
copy
1. mouseRelease(InputEvent.BUTTON3_DOWN_MASK)
• mouseMove() method will move mouse pointer to the specified
X and Y coordinates.

Example:
copy
1. robot.mouseMove(point.getX(), point.getY())
• mousePress() method will press the right click of your mouse.

Example :
copy
1. robot.mousePress(InputEvent.BUTTON3_DOWN_MASK)

36) How to execute JavaScript in Selenium?


JavaScriptExecuter is used for JavaScript execution in Selenium.
A simple example:
copy
1. WebDriver driver = new FireFoxDriver();
2. if (driver instanceof JavascriptExecutor) {
3. ((JavascriptExecutor)driver).executeScript("{JavaScript Code}");
4. }

37) Which package can be imported while working with WebDriver?


org.openqa.selenium java -cp bin;jars/* org.testng.TestNG testng.xml

38) How do you get the width of the textbox?


You can get the width of the textbox by using the following command:
copy
1. driver.findElement(By.xpath(“xpath of textbox ”)).getSize().getWidth();
2. driver.findElement(By.xpath(“xpath of textbox ”)).getSize().getHeight()

39) Which web driver implementation is the fastest?


The fastest WebDriver is HtmlUnitDriver. Differing of other drivers
(FireFoxDriver, ChromeDriver etc), it’s non-GUI, while running no browser
gets launched.
40) What is the purpose of deSelectAll() method?
It is used to deselect all the options which have been selected from the
drop-down list.

41) How can you switch back from a frame?


defaultContent() method is used to switch back from a frame.

42) How to login into any site if it’s showing any authentication
pop-up for username and password?
You should pass the username and password with URL:
https://username:password@url
https://creds:[email protected]

43) What is the purpose of getOptions() method?


getOptions() is used to get the selected option from the drop-down list.

44) What is the difference between getWindowHandles() and


getWindowHandle()?
You can get the browser address using these commands. But if you use
getWindowHandle(), you’ll get the address of the current browser
where the control is and return type is a string. So, if you use
getWindowHandles(), you will get the address of all the open browser
and its return type is an iterator.

45) Explain how you can use recovery scenario with Selenium?
You can use recovery scenario in accordance with the programming
language.
If it is Java then you can use exception handling to overcome same.

46) How do you send ENTER/TAB keys in WebDriver?


use click() or submit() methods are used for ENTER. But, don’t forget
that submit() method is used only if type=’submit’.
You can use Actions class act.sendKeys(Keys.ENTER) for TAB.
47) How to Handle Alerts in Selenium WebDriver?
Here are a few methods of Alerts handling which are widely used in
Selenium Webdriver.
• • void dismiss() is used to click on the 'Cancel' button of the alert.

copy
1. driver.switchTo().alert().dismiss();
• void accept() is used to click on the 'OK' button of the alert.

copy
1. driver.switchTo().alert().accept();
• String getText() is used to capture the alert message.

copy
1. driver.switchTo().alert().getText();
• void sendKeys(String stringToSend) is used to send some data to
alert box.

copy
1. driver.switchTo().alert().sendKeys("Text");

48) What is a data-driven framework?


The Data Driven test design framework follows a design paradigm where
test logic is fixed but varies the test data. The data itself can be in
different repositories like a simple .csv file, .json file or .xls sheet, or
database and can add the tests merely updating those external files or
DB (instead of placing in test code itself).

49) What is a keyword-driven framework?


The keyword driven framework is a methodology where actions or steps
are treated as keywords. These keywords (like click, move, type etc.,) are
stored in some external repositories along just like data (in
.csv/.json/.xls/DB).
50) What is the hybrid framework?
The combination of data driven and keyword driven framework is called
the hybrid. Here the operations/instructions/keywords in a separate
repository (.csv/.xls/.json/DB) and data is in separate (.csv/.xls/.json/db
from data provider) and the tests/driver would read both and perform
the actual tests automatically. In this design, we get the best of both
methodologies, and it is kind of practical in most of the automation
cases.

51) What are the main advantages of Selenium Grid?


Selenium Grid has following advantages: multi-browser testing, parallel
test case execution, multi-platform testing.

52) What is a hub in Selenium Grid?


Selenium Grid hub is a central point or a server that controls the test
executions on the different machines.

53) What is a node in Selenium Grid?


Selenium Grid node is a hub attached machine, which has instances
running the test scripts. Unlike a hub, there can be more than one nodes
in Selenium Grid.
83) Could you explain the line of code Webdriver driver = new
FirefoxDriver();.
‘WebDriver' is an interface and we are creating an object of type
WebDriver instantiating an object of FirefoxDriver class.

54) What is the purpose of creating a reference variable- 'driver' of


type WebDriver instead of directly creating a FireFoxDriver object
or any other driver's reference in the statement Webdriver driver =
new FirefoxDriver();?
We can use the same variable to work with multiple browsers like
ChromeDriver, IEDriver by creating a reference variable of type
WebDriver.

55) How can you create HTML test report from your test script?
There are three ways of HTML test report creation:
• using inbuilt default.html to get the HTML report in TestNG
• with the ANT help in JUnit
• using XSL jar for converting XML content to HTML in own customized
reports

56) What could be the cause of Selenium WebDriver test to fail?


There are some causes of Selenium WebDriver test to fail:
• SeleniumWebDriver element waiting to access did not appear on the
web page and the operation timed out
• SeleniumWebDriver is trying to access not created element
• SeleniumWebDriver cannot locate the element, because the locator has
been changed

57) Explain how can you debug the tests in Selenium IDE?
The tests could be debugged in such way:
• insert a break point from the location from where you want to execute
test step by step
• run the test case
• test case execution will be paused at the given break point
• click on the blue button to continue with the next statement
• to continue executing all the commands at a time click on the “Run”
button

58) What is the testng.xml file used for?


testng.xml file is used to configure the whole a test suite. Here we can
create a test suite, create test groups, mark tests for parallel execution,
add listeners and pass parameters to test scripts. It can be used for the
further test suite triggering.
89) What is the difference between @Factory and @DataProvider
annotation?
@DataProvider is concerned to individual test methods and run the
specific methods for many times.
@Factory method creates test class instances and runs all the test
methods in that class with different data. sets.
60) In which format does source view show the script in Selenium
IDE?
The script is shown by Selenium IDE source view in XML format.
61) How could AJAX controls be handled in WebDriver?
AJAX allows the Web page to retrieve small amounts of data from the
server without reloading the entire page.
The different wait methods should be applied for testing Ajax
application:
• • ThreadSleep
• • Implicit Wait
• • Explicit Wait
• • WebdriverWait
• • Fluent Wait

62) What is the FirefoxDriver, class or an interface? And which


interface does it implement?
FirefoxDriver is a Java class. It implements all the methods available in
the interface.

63) How can we make one test method dependent on other using
TestNG?
We can make one test method run only after successful execution of
dependent test method by using dependsOnMethods parameter inside
@Test annotation in TestNG: @Test(dependsOnMethods = { "preTests" })

64) How could you explain the main difference between WebDriver
and RC?
Selenium WebDriver drives the browser using built-in support. RC injects
JavaScript function into browsers when the page is loaded.

65) What is IntelliJ?


IntelliJ is an IDE that helps users to write code for Selenium better and
faster. It could be used as an option to Java bean and Eclipse.
66) What are the advantages of Using Git Hub For Selenium?
• Members of multiple people team working on the same project can
update its details and inform other team members simultaneously
• You can build the project from the remote repository regularly by using
Jenkins. This helps you to keep track of failed builds.

67) Can we use Selenium RC for tests driving on two different


browsers on one operating system without Selenium Grid?
We can do it if JAVA testing framework is not used. If we use Java client
driver of Selenium, instead of using Java testing framework, TestNG
allows us not to use Selenium Grid.
98) How can we run test cases in parallel using TestNG?
You should just to add these two key value pairs in the suite to run the
tests in parallel:
copy
1. parallel="{methods/tests/classes}"
2. thread-count="{number of threads you want to run simultaneously}".

68) How would you test your own element locator?


“Find Button” of Selenium IDE is used to test the locator. Clicking on
this button, you will see on screen if your element locator is right or
wrong.
Also, you can use “FirePath” plugin in FireFox
69) When AutoIT is used?
AutoIT is used to handle window GUI and non-HTML popups in the
application.

70) What API is required for Database Testing in Selenium


WebDriver?
JDBC (Java Database Connectivity) API is required for Database Testing
in Selenium WebDriver.

71) What Java API is required for generating pdf reports?


Java API IText is required for generating pdf reports.
72) Explain why to choose Python over Java in Selenium.
Here are some points that favor Python over Java to use with Selenium:
• Python is simpler and more compact compared to Java
• Java uses traditional braces to start and ends blocks, whilePython uses
indentation
• Java employs static typing, whilePython is dynamically typed
• Java programs tend to run slower compared toPython programs

73) How can you handle network latency using Selenium?


You can use driver.manage().timeouts().pageLoadTimeout(); for
network latency

74) How can you run Selenium Server other than the default port
4444?
Selenium server could be run on java-jar selenium-server.jar-port other
than its default port.

75) Explain how you can capture server side log Selenium Server?
To capture server side log in Selenium Server, you can use command:
java –jar .jar –log selenium.log

76) What is a framework and what are the frameworks available in


RC?
The framework is a collection of libraries and classes for helping testers
to automate test cases. NUnit, JUnit, TestNG, Bromine, RSpec, unit tests
are some of the frameworks available in RC.

77) Explain how can you insert a start point in Selenium IDE?
Selenium IDE can be set in two ways:
• in Selenium IDE right click on the command and the select “Set / Clear
Start Point”
• press “S” key on the keyboard and select the command in Selenium IDE

78) What are the two modes of views in Selenium IDE?


Selenium IDE can be opened as a pop-up window or in side bar
79) What is Object Repository?
Object repository is an essential entity in any UI automation which allows
a tester to store all object that will be used in the scripts in one or more
centralized locations rather than scattered all over the test scripts

You might also like