Advance Selenium + Core Java Interviews Flashcards

1
Q

What are the chalenges with Selenium Automation

A
  1. No Support for Non-Web Automation (Ex: If an application generates a PDF and you need to scan that pdf, Selenium cannot do it, or if you need to read a bar code -Selenium cannot do it either. It only automates things that will render on the browser!
  2. Timeout or Sync Issues
    With Selenium you give an exact timeout and after that, it may fail if the page is still loading. Ex: You indicate a timeout to the payment page on a website (5s), but the traffic is high, and it takes 10 -15 sec to load, and after 5 sec, the page is still loading- Selenium failed. Does not understand browser behavior.
  3. Test Execution Slowness in Internet Explorer
    When we ran in IE the execution time is slow.
  4. Limited reporting
    Require external tools and utility for reporting.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the Selenium 4 features?

A
  1. WebDriver is developed completely by W3C Standardization.
  2. The Selenium IDE support for Chrome is available.
  3. Selenium Grid - The hubs and nodes are smooth to set up and handle now. Once Selenium server is started, the grid will act both as a hub and node.
  4. Taking screenshots at the Element level, Section level, and Page level is possible. Ex: Possible to take a screenshot of a specific element rather than the whole page.
  5. Support of Relative Locators. Left, Right, Top, Bottom.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the difference btw WebDriver.findElement vs WebElement.findElement ?

A

driver.findElement(): Is to identify the element
It is for finding from the entire page using the given selector

WebElement.findElement();
First, it generates the the WebElement, and then the child element of the given element are searched based on the given selector. Ext: Used when you have multiple common locators on the page and you only need to drill down to unique one.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the difference btw Page Object Model and Page Factory?

A

Page Object Model(POM): Design pattern

POM is a Selenium design pattern; we can see it as a repository where we store all the WebElements. It is very easy to manage, reusability of code, and eliminates code duplication.
The key benefit if UI changes in the future, then we can update WebElements to Page Classes in POM or Object Repository Accordingly.

Page Factory: Design Pattern

Page Factory in Selenium WebDriver is an integrated concept or API. Here we follow again the same principle of keeping repository objects or page classes separate from test cases

Here we use @FindBy to find elements and to initialize WebElements using initElements process.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the locators that support selenium?

A

Name: Same as ID although is is not unique

CSS Selectors: Works on Element tags and attributes

XPath: Searches elements in DOM, Reliable but slow

Class name: Uses the class name attribute

TagName: Uses HTML tags to locate web elements

LinkText: Uses anchor text to locate web elements

Partial Link Text: Uses partial link text to find web elements

ID:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to overcome StaleElementReferenceException in Selenium?

A

Stale - Outdater
The reference to an element is now “stale”; the element will no longer appear on the page’s DOM. In simple words, when you started interacting with it, the element you located using the findElement method disappeared.

Adding exception handling to your action end, if the exception in stale, try to locate the element after a simple wait for 500 milliseconds and repeat these actions until the action or max iterations have been successful.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Difference btw XPath and SCC selectors?

A
  1. XPath is slower than CSS, whereas CSS Selectors is faster than XPath.
  2. XPath supports text though CSS Selectors does not allow text.
  3. XPath can move in both forward and backword directions whereas CSS Selector can move forward
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to access the CSS selector using the nth (child) element?

A

Here is a syntax for using the CSS selector to access the nth attribute: <type>:nth-child(n)</type>

Ex: tr:nth-child(2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly