Here, you will find most frequently and tricky asked selenium interview questions in selenium automation tool. These will definitely help you to understand the concepts with deep insights and guide you through the interview process.
Selenium interview questions and answers:
1.What is the difference between driver.get and driver.navigate function?
Driver .get () waits till the navigated URL page is completely loaded, while navigate functions do not have the page load waiting functionality.Hence, driver.get function is always preferred when we navigate to a certain URL.However, driver.navigate has additional functionalities as moving forward and moving backward, refresh the URL, etc.
2.Which locator is preferred -XPath or CSSSelector?
CssSelector locator is faster as compared to XPath .Hence, it is preferred to XPath. CssSelector provides simple and easy syntax to identify elements.
3. How to check the absence of an element while executing the remaining code?
It can be handled in 2 ways :
a .Using the selenium code
Using the above command, if the size value is zero, it means the element is not present. This command does not throw exception
b.Using Java code
Enclose the code within try-catch block and if the control goes catch block, it means the element is not present. You can define
user-defined exception too.
4. Driver.switchTo().frame() function is an example of overloading or overriding?
It is an example of overloading, as we know frame takes various data types in the argument.
Arguments list: a. int <index>
b.String < name / id>
5.What are the various ways of identifying element using CSS Selector?
e.g input[name=’password’]. It implies it will match the element which has the attribute value same as that of given value for the mentioned tag name.
e.g [name=’password] – It implies it will match the element which has the attribute value same as that which is provided irrespective of any tag name.
e.g input#password.It matches the element with given tag name and id.
e.g – # password . It matches the element which has the given id.
e.tagName.className -It matches the element which has the class name as provided.
f. .(period)className -It matches the element with the class name as provided.
6.Which plugin is necessary to execute tests in maven project?
Maven -surefire-plugin is needed to execute tests in maven project.
7.What are the various options available for a drop down ?
getOptions() -It lists down all the list of values
getAllSelectedOptions() -It lists all the selected options
selectByVisibleText(String text) -It selects that value whose text matches the text passed in the parameter
selectByVisibleValue(String value) -It selects that value whose value (attribute) matches the value passed in the parameter
selectByVisibleIndex(int index)-It selects whose index matches the index mentioned in the argument
deSelectByVisibleText(String text) -It deselects that value whose text matches the text passed in the parameter
deSelectByVisibleValue(String value) -It deselects that value whose value (attribute) matches the value passed in the parameter
deSelectByVisibleIndex(int index)-It deselects whose index matches the index mentioned in the argument
deSelectAll()-deselect all selected values in the list of values
8.How to configure maven project to execute testng.xml file ?
Configure testng.xml for suiteXmlFile in maven surefire plgin
9.What is desired capability and give examples of usage?
e.g DesiredCapabilities dc=DesiredCapabilities.internetExplorer();
Above configuration configures to accept ssl certificates.
10.How to upload file in selenium?
Uploading file can be done using following ways:
a. Passing the file path in sendKeys method to the element having tag ‘Input’ and atribute – type ‘file’
b. Using Robot class
11. How to navigate from parent to child using CSS selector?
e.g – I will explain giving an example with XPath too. Lets consider we have the following CSS selector
Same element identified using Xpath
Here in CSS Selector ,’>’ is similar to ‘/’ in xpath . ‘input’ is the tag name. ‘nth-child’ refers to nth-child of any tag (as mentioned by *) of the parent .In this case ,it is the 2nd child as pointed in the bracket.
12.How to find if the text is underlined?
13. What are the differences between Junit and TestNG?
a.Grouping of tests
c. Dependency execution
d.Before and After Test execution with @BeforeTest and @AfterSuite annotation
e.Before and After Suite execution with @BeforeSuite and @AfterSuite annotation
f.Before and After Group execution with @BeforeGroup and @AfterGroup annotation
JUnit does not support above.
14.What is the base class of web driver?
WebElement element=driver.findElement(By.XPath(” //div/input[@id=’name'”)
The first parameter in executeScript method describes the action(e.g click) of the 2nd parameter which is a web element.
Very helpful! Thanks for sharing the list of valuable Selenium Interview Questions with Answers. This article will help me to prepare for the interviews. very informative and useful article for freshers. keep sharing more article!!!