151+ Most Important Frequently Asked Selenium Interview Questions
Here we are providing 151 Most Important Frequently Asked Selenium Interview Questions. These questions will be very useful for you to crack an interview and help you to make a career in Automation Testing and Selenium.
We have divided questions in below 6 categories:
- Selenium Fundamentals:
- Selenium WebDriver
- Selenium IDE
- Selenium with Java
- Selenium with Python
- Selenium TestNG
1. Selenium Fundamentals:
Q 1: What is Selenium and why it should be selected?
Selenium is one of automation tool for web application testing. It’s an open-source with many advantages: multi-language, multi-browser testing.
Q 2: What are the limitations of Selenium?
- Only web-based application, windows application are not supported
- Mobile apps are not supported
- Sometimes, it does not work when the page is finished loading
- A programming language is required
- No options to verify images
Q 3: What are the different components of Selenium?
- Selenium IDE (Integrated Development Environment): is a plugin for recording and playing back (supported on Mozilla Firefox only)
- WebDriver and RC: APIs for almost all languages used to automate webs testing
- Grid: allows running in multiple machines
Q 4: How many browsers supported by Selenium?
So many browsers:
- Firefox
- Google Chrome
- Safari
- Internet Explorer
- iOS
- Android
Q 5: List browsers supported to run Selenium on Mac, Linux, Windows?
Safari, Opera, Chrome, Firefox
Q 6: Which programming languages supported by Selenium to write test cases?
So many languages:
- Java
- C#
- Python
- Ruby
- Perl
- PHP
Q 7: Testing type supported by Selenium?
Selenium can be used for functional test and regression test
Q 8: Do you think what is the main challenges in functional testing?
Debug issues, identify elements/object
Q 9: What is the Selenium recording language?
HTML
Q 10: Define steps to run automation using Selenium?
- Step1: record test steps by selenium-IDE
- Step2: Revise the script according to your test purpose.
- Step3: Run your test
- Step4: View results and analyze fails
Q 11: What is the default port number of Selenium Server?
It’s 4444
Q 12: What are the 3 main components of Selenium testing tool?
Selenium RC, Selenium IDE, Selenium Grid
Q 13: What are the 4 parameters you must pass in Selenium?
URL, port number, host, browser
Q 14: How can you manage the code version in Selenium?
Use svn or GitLab,…
Q 15: What is the syntax of Selenium command?
Three entities associated with a command:
- Name of commands
- Element locator
- Value
Q 16: Why we should use Selenium Grid?
We use it to execute tests on many browsers and platforms to save time
Q 17: What is the main difference between Selenium 1 and Selenium 2?
It is WebDriver, Selenium 2 is a combination of Selenium 1 and WebDriver
Q 18: Give an example that we can’t automate in Selenium?
Captcha, barcode
Q 19: Does Selenium support https protocols?
Yes
Q 20: List some types of text patterns available in Selenium?
globbing, exact, regular expressions
Q 21: What is the difficulties that you faced in object identification?
Some elements were not recognized properly using Selenium WebDriver.
2. Selenium WebDriver
Q 22: Which operating systems support Selenium WebDriver?
- Windows
- Apple OS X
- Linux
Q 23: What is the cost of Selenium WebDriver?
No, it’s an open source, free of cost.
Q 24: Does Selenium WebDriver support record and playback?
No, it does not support, only Selenium IDE
Q 25: When we use an action class in Selenium WebDriver?
We use it to slide, resize, drag and drop an element.
Q 26: What is the default time value for Selenium IDE and Selenium WebDriver?
It is 30 seconds
Q 27: How to find a broken image in Selenium WebDriver?
Perform a GET request on the image, and verify the response status code, if it is 404/500, it is a broken image
Q 28: How to capture Screen Shot in Selenium WebDriver?
File myfile= ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(myfile, new File(“c:\\name.png”));
Q 29: How do I use html id and name in Selenium WebDriver?
No, you can not use them in WebDriver, they are used in Selenium IDE
Q 30: How to get the attribute value in Selenium WebDriver?
Use getAttribute() method:
WebDriver my_webdriver = new FirefoxDriver();
my_webdriver .get(“https://www.mysite.com”);
my_webdriver .findElement(By.id(“my_id”)). getAttribute(“value”);
Q 31: How to click on an element using Selenium WebDriver?
Use click() method:
WebDriver my_webdriver = new FirefoxDriver();
my_webdriver .get(“https://www.mysite.com”);
my_webdriver .findElement(By.id(“my_id”)). click();
Q 32: How to launch a browser using WebDriver?
To launch Firefox browser:
WebDriver driver = new FirefoxDriver();
To launch Chrome browser:
WebDriver driver = new ChromeDriver();
To launch IE browser:
WebDriver driver = new InternetExplorerDriver();
Q 33: How many waits available in WebDriver?
3 main waits: implicit wait, explicit wait, fluent wait
Q 34: What is implicit wait in WebDriver?
Wait for a certain amount of time before it continue next steps
Q 35: What is explicit wait in WebDriver?
Wait in a certain time until the expected element is visible if no, it will throw a “No Such Element Exception”.
Q 36: Can we test mobile applications on WebDriver?
No, WebDriver does not support to test mobile applications
Q 37: Which is the fastest WebDriver?
It could be HTML Unit Driver and it’s non GUI
Q 38: How to send Enter key in WebDriver?
Use 2 methods:
. Use click()
. Use sendKeys(Keys.ENTER)
Q 39: Does WebDriver support third party driver? Example?
Yes, it supports SeleniumHQ drivers and third party driver: IphoneDriver, AndroidDriver, OperaDriver, ChromeDriver
Q 40: What is HtmlUnitDriver?
It is a java based implementation of a web browser without a GUI also one of the drivers of Selenium WebDriver, fastest and most lightweight implementation of WebDriver.
Q 41: What are the advantages of HtmlUnitDriver?
- Support Javascript
- Allow selecting another browser version in the test script
- Fastest implementation of WebDriver
3. Selenium IDE
Q 42: What are two mode views in Selenium IDE?
In side bar: View>Side bar>Selenium IDE or a popop windows: Tool>Selenium IDE
Q 43: Can I control the speed of test execution if Selenium IDE?
Yes, Selenium IDE provides a slider with Slow and Fast pointers to control the speed
Q 44: What is Selenese?
Selenese is the language which is used to write test scripts in Selenium IDE
Q 45: How to edit tests in Selenium IDE?
Two ways to edit: one is table view, other way is look into the source code of recorded command
Q 46: What are 3 main components of Selenium IDE?
Command, value and target
Q 47: What is the difference between Selenium core extensions and Selenium IDE extensions?
Selenium core extensions are the default functionality in Selenium library, can be downloaded and make uses of action, locator and assertion. Selenium IDE provides the feature to extend your record and play button
Q 48: Can we use html id in Selenium IDE?
Yes, we can use both in Selenium IDE
Q 49: What is the language used in Selenium IDE?
It’s Selenese
Q 50: Does Selenium IDE supports Chrome?
No, because it is a Firefox plugin, so it supports on Firefox only
Q 51: What is IntelliJ?
It’s an IDE, used to be an option to Eclipse and Java bean, help you write Selenium code faster and better
4. Selenium with Java to interact elements
Q 52: How can we find an element using Selenium?
There are different ways to find an element in a web page they are
- ID
- Name
- Tag
- Attribute
- CSS
- Linktext
- PartialLink Text
- Xpath
Q 53: What is an Accessor in Selenium?
Accessor is one of the type of Selenium, used for storing the value of the target in a variable, and used for evaluating the result in a variable
Q 54: What is an Xpath?
It is a query language , used to find the Web element in corresponding web pages (locate a web element based on its XML path). It is also useful in identifying the dynamic elements.
Q 55: What is an absolute Xpath?
An absolute XPath locates an element using an XML expression beginning from root node.
Example: html/body/div/div[3]/div/div/div/div[2]/div
Q 56: What is a relative XPath?
A relative XPath locates an element using an XML expression beginning from anywhere in the HTML document.
Example: //input[@id=’email’
Q 57: What is the difference between “/” and “//” in Xpath?
Single Slash “/”: allow to create Xpath with absolute path (the Xpath would be created to start selection from the document node/start node)
Double Slash “//”: allow to create Xpath with relative path (the Xpath would be created to start selection from anywhere within the document)
Q 58: What is assertion in Selenium and what are the types of assertion?
Assertion is used as a verification point. It verifies that the state of the application conforms to what is expected. The types of assertion are “assert” , “verify” and “waitFor”.
Q 59: What is the difference between TypeKeys() and type() ?
TypeKeys() will call Javascript event whereas type() won’t, typekeys() emulates like actual user typing.
Q 60: How can we inspect the web element attributes?
Use developer tools we can inspect the specific web elements to use them in different locators or you can use Firebug – a plugin of firefox.
Q 61: Differentiate between verify and assert commands?
assert() checks whether an element is present on the page or not. The test will stop if the check fails. verify() command checks whether the element is on the page. The test will not stop if the element is not present.
Q 62: How can I submit a form using Selenium?
WebElement we = driver.findElement(By.id(“ElementID”);
we.submit();
Q 63: How to execute java scripts function?
JavascriptExecutor js = (JavascriptExecutor) driver;
String title = (String) js.executeScript(“pass”);
Q 64: How to get radio button in Selenium?
WebElement el = driver.findElement(By.id(“Radio button id”));
Q 65: How to capture page title using Selenium?
String mytitle = driver.getTitle();
Q 66: How to store page source using Selenium?
String my_pagesource = driver.getPageSource();
Q 67: How to get current url using Selenium?
String my_currentURL = driver.getCurrentUrl();
Q 68: How to find an element if it is displayed on the screen?
Use isDisplayed(): boolean mybutton = driver.findElement(By.id(“id1”)).isDisplayed();
Use isSelected(): boolean mybutton = driver.findElement(By.id(“id2”)).isSelected();
Use isEnabled(): boolean mybutton = driver.findElement(By.id(“id3”)). isEnabled();
Q 69: Can we double click on element using Selenium?
Yes, we can, by using Actions.doubleClick()
Q 70: How can we get a text of a web element?
String wanted_text = driver.findElement(By.id(“id1”)).getText();
Q 71: What is the API to get maximum of window?
driver.manage().window().maximize()
Q 72: When we use findElement() and findElements()?
. findElement(): used to find the first element in the current web page matching with your expected value
. findElements(): used to find all the elements in the current web page matching with your expected
Q 73: Can we test windows based pop up with Selenium?
No, it supports only for web application testing
Q 74: If we can not test windows based pop up with Selenium, how can we handle it?
We can use Alert interface
Q 75: Can we verify PDF content with Selenium?
Yes, use PDFParser via Selenium WebDriver
Q 76: How to asset a title of the web page?
get the title by getTitle() then use assertTrue()
Q 77: List some assertion states in Selnium?
assertTextPresent, assertText, assertTitle, assertValue, assertElementPresent
Q 78: List some waitfor command?
waitForPageToLoad, waitForAlert, waitForTable, waitForTitle, waitForText, waitForPopup
Q 79: How can we prioritize test method?
By adding annotation, example:
@Test(priority=0)
@Test(priority=1)
=> Mean test method with priority 0 will be executed first then the test method with priority 1 will be executed.
Q 80: How can we pass credentials to an authentication popup in Selenium?
Example: http://user:[email protected]
Q 81: List some exceptions in Selenium?
TimeoutException, NoSuchElementException, ElementNotVisibleException, StaleElementException
Q 82: Explain this line of code?
WebDriver driver = new ChromeDriver();
driver: a variable of WebDriver interface
We are creating a new object of ChromeDriver and store it into driver variable
Q 83: What is the main difference between Xpath and CSS Selector?
Xpath supports both forward and backward, while CSS selector supports only forward
Q 84: How can we use id as a CSS Selector?
#<your_id>
Q 85: How can we use a class as a CSS Selector?
<your_class>
Q 86: What is the difference between soft and hard assert in Selenium?
Soft assert: admits the errors during the test execution, if it fails, next steps will be executed
Hard assert: immediately responds with an AssertException, the next steps will NOT be executed, jump to the next case
Q 87: How can we enter text to html text box using Selenium?
use sendKey() method:
WebDriver my_webdriver = new FirefoxDriver();
my_webdriver .get(“https://www.mysite.com”);
my_webdriver .findElement(By.id(“my_id”)).sendKeys(“My text”);
Q 88: How to clear all content in html text box using Selenium?
use clear() method:
WebDriver my_webdriver = new FirefoxDriver();
my_webdriver .get(“https://www.mysite.com”);
my_webdriver .findElement(By.id(“my_id”)).sendKeys(“My text”);
my_webdriver .findElement(By.id(“my_id”)).clear();
Q 89: How to get the value of html text box using Selenium?
use getText() method:
WebDriver my_webdriver = new FirefoxDriver();
my_webdriver .get(“https://www.mysite.com”);
my_webdriver .findElement(By.id(“my_id”)). getText();
Q 90: What is the difference between close() and quit() commands?
- close(): close the current web browser window
- quit(): close all web browser windows that have been opened
Q 91: Can we delete session cookies?
Yes, by using deleteAllCookies()
WebDriver my_webdriver = new FirefoxDriver();
my_webdriver .manage().deleteAllCookies();
Q 92: What is the difference between getWindowHandle() and getWindowHandles() methods?
- getWindowHandle(): returns a handle of the current web page
- getWindowHandles(): returns a handle of all web pages available
Q 93: How to verify an object on all pages?
Use isElementPresent() method:
WebDriver my_webdriver = new FirefoxDriver();
Selenium my_selenium = new WebDriverBackedSelenium(my_webdriver, something2);
assertTrue(my_selenium .isElementPresent(“text”));
Q 94: How to handle pop-ops in Selenium?
Following APIs:
Dismiss(): simulate the Cancel button.
Accept(): simulate the Okay button.
GetText(): get the text shown by the pop-ops.
SendKeys(): send keystrokes to the currently active window
Q 95: What API is required for Database testing in Selenium?
It is Java Database Connectivity API
Q 96: Which programming language do we prefer in Selenium?
We prefer to use Java with the following reasons:
- Faster than other popular languages like Python
- It’s more widely used in commercial applications, so easy to integrate
- . Easy to find document for the support
Q 97: Give me the name of the super interface in WebDriver?
It is SearchContext
Q 98: How can we get color in WebDriver?
Use getCssValue(‘color’)
Q 99: How can we switch between frames?
Use driver.switchTo().frame(arg). With arg is one of below:
. An index of frame
. A name or ID of the frame
Q 100: How can we upload a file using Selenium?
Use sendKeys()
WebDriver my_webdriver = new FirefoxDriver();
WebElement we = my_webdriver.findElement(By.id(“myid”));
we.sendKeys(“D:\\myfile.html”);
Q 101: How can we handle frame using Selenium?
Use SwitchTo() method
Q 102: How can we display a string or a value into log?
Use echo <string> or echo $<value>
Q 103: How to create html test report?
Three ways: using TestNG, Junit, Extent Library.
Q 104: Your script in Selenium will be shown in html?
No, in XML format
Q 105: FirefoxDriver is a class or interface?
FirefoxDriver is a class which implement all methods in the interface
Q 106: How to know whether checkbox/radio is checked or not?
Use isSelected() method to know.
Q 107: How to read excel file?
Use POI API or JXL
Q 108: Could you explain this line: Webdriver my_driver = new FirefoxDriver()
We are creating an object of a class FirefoxDriver by taking reference of a WebDriver interface
Q 109: What is the way to log in a site?
Use click() on login button or submit() (only with attribute type =submit)
Q 110: What is the testing.xml file?
This file used for configuring the whole test suite (create test suite/test group/setup parallel exceptions)
Q 111: How to refresh the browser in Selenium?
sendKeys(Keys.F5)
navigate().refresh()
Q 112: When we use deselecting all() method?
When we want to deselect all the selected options from the drop down list
Q 113: What is the difference between @Factory and @Data Provider annotation?
. @Factory: create a test class and run all the test methods
. @Data Provider: individual test method/specific test method
Q 114: When we use getOptions() method?
When we want to get all the selected options from the drop down list
Q 115: How to handle network latency in Selenium?
WebDriver my_webdriver = new FirefoxDriver();
webdriver.manage().timeouts().pageLoadTimeout();
Q 116: How to mouse hover over an element in Selenium?
WebDriver my_webdriver = new FirefoxDriver();
Actions my_action = new Actions(my_webdriver);
WebElement we=my_webdriver.find Element(By.id(“element Id”));
my_action. move To Element(we).perform();
Q 117: How to open Firefox browser in Selenium?
WebDriver my_webdriver = new FirefoxDriver();
Q 118: What is difference between @beforeclass and @beforemethod?
@beforeclass: it means precondition, it will be executed once, before any test methods in the class
@beforemethod: will be executed every time before test method
Q 119: How to run tests as following: Test1-Test2-Test3?
Use priority:
@Test(priority=1)
public void Test1(){System.out.print(“This is Test1”);
@Test(priority=2)
public void Test2(){System.out.print(“This is Test2”);
@Test(priority=3)
public void Test3(){System.out.print(“This is Test3”);
Q 120: How to change port number in Selenium?
Use setPort() method
RemoteControlConfiguration rc= new RemoteControlConfiguration();
rc.setPort(4578);
SeleniumServer s= new SeleniumServer(rc);
Q 121: When we use contectClick() method?
When we want to do right click
Q 122: How to find more than one web element in the list using Selenium?
Use WebElementList to find more than a web element
Q 123: How to conduct data driven testing?
Use excel file and add third party excel jar file
Q 124: How to know a dropdownList supports multiple selections?
Use isMultiple() method
Q 125: How to identify an object in Selenium?
Use String Locator function
Q 126: How to insert a document into another document?
Use iframe command.
Q 127: What Headless browser is called?
It’s HTMLUnitDriver
Q 128: Do you think Xpath is better than CSS?
No, CSS selector is better than XPath due to its simplicity, speed, and performance.
Q 129: How to navigate to a specified URL?
Use navigate().to() method
Q 130: What are Breakpoints and Start points in Selenium?
Both of them help you to check that your code is working as expected.
Breakpoints: notice that where the execution will stop.
Start points: notice that where the execution will start.
Q 131: How to set page load timeout in Selenium?
2 ways to do: SetPageLoadTimeout(), WebDriverWait
Q 132: How to turn off Javascript in Selenium?
Set ‘javascript.enabled’ attribute to false:
FirefoxProfileManager fm = new FirefoxProfileManager();
FirefoxProfile fp = fm.GetProfile(“ABC”);
fp.SetPreference(“javascript.enabled”, false);
this.driver = new FirefoxDriver(fp);
Q 133: Can we use Java to generate PDF report?
Yes, we can use Java API Itext
Q 134: How to capture server side log?
Use java -jar selenium-standalone.jar
Q 135: How to convert String to Char?
Use toCharArray()
Q 136: What about OOPS Concepts?
- Polymorphism
- Encapsulation
- Inheritance
- Abstraction
Q 137: What is the difference between HashTable and HashMap in java?
- HashMap can have a Null key and Multiple Null values
- HashTable can not have Null key and Null values.
5. Selenium Python
Q 138: How to define a new function with Python in Selenium?
def funtionName: function body
Q 139: In Python, what is the simple command to delay test execution in 5 seconds?
import time
time.sleep(10)
Q 140: How to get an element and write texts?
my_driver.find_element_by_name(“q”).send_keys(“MYNAME”)
Q 141: How to convert string to integer and integer to string in Python?
- string to int: use int() method, example: int(“10”)
- int to string: use str() method, example: str(10)
Q 142: How to know a button is disabled or enabled in WebDriver?
my_element = driver.find_element_by_name(“my_name”).is_enabled()
Q 143: What is pass in python.
It means no operation to be done
Q 144: List some supported data types in Python?
Integer, string, fload
Q 145: How to fetch the current URL in selenium
my_driver.current_url: returns the current url of the browser
Q 146: How to handle exception in Python?
Use:
try:
except
Example:
try:
webElement = driver.find_element_by_id(“my_id”)
webElement.click()
except NoSuchElementException as exception:
print “Element not found”
Q 147: How to find multiple elements by name in Python?
Use this method: find_elements_by_name
Example:
from selenium import webdriver
my_driver = webdriver.Firefox()
my_driver.find_elements_by_name(“myname”)
Q 148: Can we locate elements by CSS Selector?
Yes, we can use this method: find_element_by_css_selector
Example:
from selenium import webdriver
my_driver = webdriver.Firefox()
my_driver .find_element_by_css_selector(‘p.content’)
Q 149: How to take screenshot of the current window in Python?
from selenium import webdriver
my_driver = webdriver.Firefox()
driver.save_screenshot(‘screenshot1.png’)
6. Selenium TestNG
Q 150: What are the features of TestNG?
. Supports annotations.
. TestNG uses more Java and OO features.
. Flexible runtime configuration.
. Supports testing integrated classes
Q 152: Why should use TestNG with Selenium?
Use it to generate test results, because default Selenium does not generate a proper format for the test results
Q 153: Why should use TestNG rather than Junit?
. Can parallel testing
. Group test cases more easy
. Annotation is easy to understand
Q 154: What does @BeforeSuite do?
Notice that this below method will be run before all tests in this test suite.
Q 156: What does @Test do?
Notice that this below method is a test case
Q 157: Example of listeners in TestNG in Selenium?
ITestListener, ISuiteListener, IAnnotationTransformer, IexecutionListener
Q 158: How to skip a test in TestNG?
Use @Test(enabled=false) annotation
Q 159: How can we customize a TestNG report?
We can do it via ITestListener interface or IReporter Interface
Q 160: What is the sequence of execution of the annotations in TestNG?
It must be as below:
@BeforeSuite
@BeforeTest
@BeforeClass
@BeforeMethod
@Test
@AfterMethod
@AfterClass
@Aftertest
@AfterSuite
Q 161: How to run a single TestNG using maven?
Use below command:
mvn -Dtest=Test_Class#Test_Method test
Q 162: How to run a set of TestNG group using maven?
Use below command:
mvn test -Dgroups=group1,group2
Conclusion:
Please let us know if you need any answers to your questions. Happy to help you.
All The Best !!!