HomeAutomation

Selenium Java Interview Questions And Answers – Part 2

Selenium Java Interview Questions And Answers – Part 2

Selenium Java Interview Questions and Answers Part-2

1) What are the different types of navigation commands in Selenium?

Different navigation commands in selenium are:

– navigate().to();

-navigate().forward();

-navigate().back();

-navigate().refresh();

2) How to fetch the current page URL in Selenium WebDriver?

We can use the getCurrentUrl() method to get the current page URL.

3) How can we maximize browser window in Selenium WebDriver?

We can use the maximize() method to maximize browser window.

4) How to delete cookies in Selenium?

We can use deleteAllCookies() method to delete cookies in selenium.

5) What are the different ways for refreshing the page using Selenium WebDriver?

Browser refresh operation can be performed using the following ways in Selenium:

– Refresh method

– Get method

-Navigate method

-SendKeys method

6) What is the difference between driver.getWindowHandle() and driver.getWinowHandles() in Selenium WebDriver and their return type?

driver.getWindowHandle()  – To get the window handle of the current window. Returns a string of alphanumeric window handle

driver.getWinowHandles() – To get the window handle of all current windows. Return a set of window handles

7) How to handle hidden elements in Selenium WebDriver?

We can use the JavaScriptExecutor to handle hidden elements.

8) How can you find broken links in a page using Selenium WebDriver?

9) How to find more than one web element in the list?

We can find more than one web element by using the findElements() method in Selenium.

10) How to read a JavaScript variable in Selenium WebDriver?

11) What is JavascriptExecutor and in which case JavascriptExecutor will help in Selenium automation?

JavaScriptExecutor is an Interface that helps to execute JavaScript through Selenium Webdriver.

In case, when selenium locators do not work you can use JavaScriptExecutor. You can use JavaScriptExecutor to perform a desired operation on a web element.

12) How to handle Ajax calls in Selenium WebDriver?

The best approach would be to wait for the required element in a dynamic period and then continue the test execution as soon as the element is found/visible. This can be achieved with WebDriverWait in combination with ExpectedCondition , the best way to wait for an element dynamically, checking for the condition every second and continuing to the next command in the script as soon as the condition is met.

13) List some scenarios which we cannot automate using Selenium WebDriver?

-Bitmap comparison is not possible using Selenium WebDriver.

-Automating Captcha is not possible using Selenium WebDriver.

-We can not read bar code using Selenium WebDriver.

-We can not automate OTP submission.

14) How you build object repository in your project framework?

We can build object repository using Page Object Model or Page Factory.

15) What is Page Object Model (POM) and its advantages?

Page Object Model is a design pattern for creating an object repository for web UI elements. Each web page in the application is required to have its own corresponding page class. The page class is thus responsible for finding the WebElements in that page and then perform operations on those web elements.

The advantages of using POM are:

-Allow us to separate operations and flows in the UI from verification – improves code readability

-Since the Object Repository is independent of test cases, multiple tests can use the same object repository

-Reusability of code

16) What is Page Factory?

Page Factory class in Selenium is an extension to the Page Object Design pattern. It is used to initialize the elements of the page object or instantiate the page objects itself.

Annotations in Page Factory are like this:

OR

We need to initialize the page object like this:

17) What is the difference between Page Object Model and Page Factory?

Page Object Model is a design pattern to create an Object Repository for web UI elements. However, Page Factory is a built-in class in Selenium for maintaining object repository.

18) What are the advantages of Page Object Model?

The advantages of using Page Object Model are:

-Allow us to separate operations and flows in the UI from verification – improves code readability

-Since the Object Repository is independent of test cases, multiple tests can use the same object repository

-Reusability of code

19) How can we use Recovery Scenario in Selenium WebDriver?

We can develop Recovery scenarios using exception handling i.e. By using “Try Catch Block” within your Selenium WebDriver Java tests

20) How to upload a file in Selenium WebDriver?

Uploading files in WebDriver is done by simply using the sendKeys() method on the file-select input field to enter the path to the file to be uploaded.

21) How to download a file in Selenium WebDriver?

Step 1- Create a firefox Profile.

Step 2- set Preferences as per requirement.

Step 3- Open Firefox with firefox profile.

22) How to run Selenium WebDriver tests from command line?

23) How to switch to frames in Selenium WebDriver?

For switching between frames, use driver.switchTo().frame(). First locate the frame id and define it in a WebElement.

Ex:

24) How to connect to a database in Selenium?

25) How to resize browser window using Selenium WebDriver?

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.

 

If you like this article, share it on LinkedIn using the below button:

Comments (0)

Leave a Reply

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