Selenium Java Interview Questions And Answers – Part 11

Selenium Java Interview Questions And Answers – Part 11

Selenium Java Interview Questions and Answers Part-11

1) How to get the html source code of a particular web element using Selenium WebDriver?

We can get the html source code of an element using getAttribute method.



2) What are the different driver classes available in Selenium WebDriver API?

Selenium WebDriver API consists of different types of Browser driver classes like ChromeDriver,IEDriver, FirefoxDriver, etc…

3) What automation tools could be used for post-release validation with continuous intergration?

We can use continuous monitoring tools such as Nagios and Splunk to perform post release validation.

4) Does the latest version of Selenium WebDriver support Mobile Testing?

Selenium directly doesn’t support Mobile testing but it is possible by the help of other tools like Appium.

5) What is the major differences between XPath Expressions and CSS Selectors?

Using XPath we can traverse both forward and backward whereas CSS selector only moves forward in HTML DOM.

6) How to select a check box in Selenium?

We can select a checkbox by clicking on it.



7) How to verify whether the checkbox option or radio button is selected or not?

By using isSelected() method.



8) What is the alternative way to click on login button?

We can use JavaScriptExecutor to click on login button.

JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", button);


9) How can you find the value of different attributes like name, class, value of an element?

By using the getAttribute() method.

String name = driver.findElement(By.id("login")).getAttribute("name");


10) How to verify whether a button is enabled on the page?

We can verify by using isEnabled() method.



11) What kind of mouse actions can be performed using Selenium?

Following mouse actions can be performed:
– doubleClick(): Performs double click on the element
– clickAndHold(): Performs long click on the mouse without releasing it
– dragAndDrop(): Drags the element from one point and drops to another
– moveToElement(): Shifts the mouse pointer to the center of the element
– contextClick(): Performs right-click on the mouse

12) What kind of keyboard operations can be performed in Selenium?

Following keyboard actions can be performed:
– sendKeys(): Sends a series of keys to the element
– keyUp(): Performs key release
– keyDown(): Performs keypress without release

13) Can Bar Code Reader be automated using Selenium?

It is not possible to automate bar code reader in Selenium.

14) How to locate a link using its text in Selenium?

We can use By.linkText() to locate a link using text in Selenium.

15) Write the program to locate/fetch all the links on a specific web page?

List<WebElements> allLinks = driver.findElements(By.tagName("a"));


16) How can we run test cases in parallel using TestNG?

By using the parallel attribute in testng.xml. The parallel attribute of suite tag can accept four values:

– tests: All the test cases inside <test> tag of Testing xml file will run parallel.
– classes: All the test cases inside a Java class will run parallel
– methods: All the methods with @Test annotation will execute parallel.
– instances: Test cases in same instance will execute parall

17) How do you get the height and width of a text box field using Selenium?

We can get the height and width of a text box using getSize() method.

WebElement element = driver.findElement(By.id("txt"));


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

Following package can be imported: org.openqa.selenium.WebDriver

19) What is the purpose of deselectAll() method?

Clears all selected entries. This is only valid when the SELECT supports multiple selections.

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

It Returns all the option elements displayed in the select tag for dropdown list.

21) How to handle alerts in Selenium WebDriver?

We can use switchTo().Alert() method to switch to the alert dialog and perform the below actions:

driver.switchTo.Alert().accept(); //To click on Ok button of alert
driver.switchTo().Alert().dismiss(); //To click on Cancel button of alert


22) What is hybrid framework?

Hybrid Framework is a combination two or more frameworks like Data-Driven, Modular or Keyword-Driven. It uses the best features of each framework to build a highly reusable and maintainable framework.

23) Can you explain the line of code WebDriver driver = new FirefoxDriver();?

It starts a new Firefox browser driver instance.

24) What could be the cause for Selenium WebDriver test to fail?

There could be many reasons for test failure. Some of them are listed below:
– Driver is null or not found
– Element is not found on the page
– Element is present but not interactable
– Page Synchronization issues

25) What is the difference between @Factory and @DataProvider annotation?

@DataProvider – A test method that uses @DataProvider will be executed multiple number of times based on the configuration provided in it.
The test method will be executed using the same instance of the test class to which the test method belongs.
@Factory – A factory will execute all the test methods present inside a test class using separate instances of the class.

Next Steps:

> More interview questions and answers on Selenium Java, continue to the next post (Click on Next Post link below)

> Check complete Selenium Java interview questions and answers here (Click here)

Please leave your questions/comments/feedback below.

Happy Learning ?

About Me > Bijan Patel

Connect to me on Linked In (Click here)

On a mission to contribute to the Software Testing Community in all possible ways.

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

For FREE Testing Tutorials & Videos

Open chat
Contact Us on Whatsapp