Selenium Flashcards

1
Q

What is Selenium WebDriver?

A

Was the first cross-platform testing framework that could configure and control the browsers on the OS level. It served as a programming interface to create and run test cases.

WebDriver performs actions on web elements. It supports various programming languages like Java, C#, PHP, Python, among others. It can also be integrated with frameworks like TestNG and JUnit for test management

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

What is Selenium Grid?

A

A grid with the primary objective of minimizing the test execution time. This was facilitated by distributing the test commands to different machines simultaneously. Selenium Grid allows the parallel execution of tests on different browsers and different operating systems. Grid is exceptionally flexible and integrates with other suite components for simultaneous execution.

========

The Grid consists of a hub connected to several nodes. It receives the test to be executed along with information about the operating system and browser to be run on and picks a node that conforms to the requirements (browser and platform), passing the test to that node. The node now runs the browser and executes the selenium commands within it.

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

**Advantages of Selenium Testing **

A
  1. Selenium has proven to be accurate with results thus making it extremely reliable
  2. Since selenium is open-source, anybody willing to learn testing can begin at no cost
  3. Selenium supports a broad spectrum of programming languages like Python, PHP, Perl, and Ruby
  4. Selenium supports various browsers like Chrome, Firefox, and Opera, among others
  5. Selenium is easy to implement and doesn’t require the engineer to have in-depth knowledge of the tool
  6. Selenium has plenty of re-usability and add-ons
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Limitations of Selenium Testing

A
  1. Since Selenium is open-source, it doesn’t have a developer community and hence doesn’t have a reliable tech support
  2. Selenium cannot test mobile or desktop applications
  3. Selenium offers limited support for image testing
  4. Selenium has limited support for test management. Selenium is often integrated with tools like JUnit and TestNG for this purpose
  5. You may need knowledge of programming languages to use Selenium
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is XPath?

A

XPath is a Selenium technique that is used to navigate through the HTML structure of a webpage. It is a syntax or language that makes finding elements on a webpage possible using XML path expression.

In Selenium automation, there may be times when elements cannot be found with general locators like ID, name, class, etc. And this is when XPath is used to locate those elements on the webpage. XPath in Selenium may be used on both XML and HTML documents.

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

Syntax of XPath

A

Syntax of XPath
XPath in Selenium provides many essential XPath functions and axes to write effective XPaths of the web elements and define unique locators.

XPath = //tagname[@Attribute = ‘Value’]

// : to select the current node.
tag name: tag name of a specific node.
@: to select the attribute.
attribute: it is the attribute name of the node.
value: it is the value of the node.

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

Types of XPath Locators

A
  1. ID - Find the element using the ID of the element
  2. Classname - Find the element using the class name of the element
  3. Link Text - Find the element using the text of the link
  4. Name - Find the element using the name of the element
  5. XPath - Required to find the dynamic element and to traverse between different elements of the web page
  6. CSS path - Locates elements that have no class. name, or ID
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Types of XPath

A

Absolute XPath refers to the direct way of finding an element. The major drawback of Absolute XPath is that if there are any changes in the element’s path, then the XPath will fail.

The XPath begins with a single forward-slash (/), which states that the element can be selected from the root node.

Absolute XPath:/html/body/div[1]/div/div[2]/header/div/div[2]/a/img

==========

Relative XPath, the path begins from the middle of the HTML DOM structure. Here, the structure starts with a double forward-slash (//) that states that the element can be searched anywhere on the webpage.

Relative XPath enables you to write from the middle of the HTML DOM structure without any need to write a long XPath.

Relative XPath://*[@id=”block-perfecto-main-menu”]/ul/li[6]/a

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

XPath Contains() function

A

The XPath Contains() is a function used to create an XPath expression. It is used if part of the value of any attribute changes dynamically, like login information, etc. The function can navigate to the web element with the partial text present.

//tag_name[contains(@attribute,’value_of_attribute’)]

The Contains() method accepts two parameters:

  • The attribute of the tag must validate to locate the web element.
  • The value of an attribute is a partial value that the attribute must contain.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

XPath Text() function

A

The XPath Text() is a function used to locate the element on a web page using the web element’s text. The function proves its worth if the element contains a text, like a label, etc.

//tag_name[text()= ’Text of the element’]

The text() method here returns the text of the web element when identified by the tag_name, and compared with the value provided on the right side.

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

XPath Starts-with() function

A

The XPath Starts-with() function is used to find the element in which the attribute value starts with some specific character or a sequence of characters. The function plays a major role while working with the dynamic web pages.

/tag_name[starts-with(@attribute,’Part_of_Attribute_value’)]

The Starts-with() accepts two parameters:

The attribute of the tag must validate to locate the web element.
The attribute value is the partial value of the attribute with which the attribute is expected to start.

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

What Are XPath Axes?

A

All the XML DOM elements are in a hierarchical structure and can be either located using Absolute paths or Relative paths. For this, XPath provides specific attributes called “XPath Axis.”

Here, an axis shows a relationship to the current node and helps locate the relative nodes concerning the tree’s current node. So, the XPath Axis uses the relation between several nodes to find those nodes in the DOM structure.

Let’s have a look at some Axis that helps in locating the elements on the webpage:
ancestor - To locate the ancestors of the current node, including the parent node and the root node
ancestor-or-self - To locate the current node along with its ancestors
attribute - To specify the attributes of the current node
child - To locate the child/children of the current node
descendant - To locate the children of the current node up the leaf node
descendant- or-self - To locate the current node with its descendants
following - To locate all the nodes that come after the current node
parent - To locate the parent of the current node
self - To locate the current (present) node

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

What is the same-origin policy and how is it handled?

A

Same Origin policy is a feature adopted for security purposes. According to this policy, a web browser allows scripts from one webpage to access the contents of another webpage provided both the pages have the same origin. The origin refers to a combination of the URL scheme, hostname, and port number.

The same Origin Policy prevents a malicious script on one page to access sensitive data on another webpage.

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

What is Selenese? How is it classified?

A

Action: Commands which interact directly with the application

Accessors: Allow the user to store certain values to a user-defined variable

Assertions: Verifies the current state of the application with an expected state

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

What are the types of waits supported by WebDriver?

A
  1. Implicit wait - Implicit wait commands Selenium to wait for a certain amount of time before throwing a “No such element” exception.` driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS);`
  2. Explicit wait - Explicit wait is used to tell the Web Driver to wait for certain conditions before throwing an “ElementNotVisibleException” exception.
      WebDriverWait wait = 
             new WebDriverWait(WebDriver Reference, TimeOut);
  3. Fluent wait - It is used to tell the web driver to wait for a condition, as well as the frequency with which we want to check the condition before throwing an “ElementNotVisibleException” exception.Wait wait = new FluentWait(WebDriver reference).withTimeout(timeout, SECONDS).pollingEvery(timeout, SECONDS).ignoring(Exception.class);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Mention the types of navigation commands

A
  1. driver.navigate().to(“https://www.ebay.in/”); - Navigates to the provided URL
  2. driver.navigate().refresh(); - This method refreshes the current page
  3. driver.navigate().forward(); - This method does the same operation as clicking on the Forward Button of any browser. It neither accepts nor returns anything.
  4. driver.navigate().back(); - This method does the same operation as clicking on the Back Button of any browser. It neither accepts nor returns anything.
16
Q

What is the major difference between driver.close() and driver.quit()?

A
  1. driver.close()This command closes the browser’s current window. If multiple windows are open, the current window of focus will be closed.
  2. driver.quit()
    When quit() is called on the driver instance and there are one or more browser windows open, it closes all the open browser windows.
17
Q

What do you mean by the assertion in Selenium?

A

An assertion is a method of testing whether a particular condition is true or false. In Selenium, assertions are used to verify the state of elements on a page or the results of an action. Assertions can be used to check for the presence or absence of an element, the value of an element, or the text of an element. Assertions can also be used to check that an element is visible or hidden.

Assertions are an important part of testing with Selenium, as they enable you to verify that the state of your application meets your expectations. Without assertions, it would be difficult to know whether or not your tests are actually passing or failing.

18
Q

Explain the difference between assert and verify commands.

A

The assert command is used to check if the given condition is true or not. If the condition is true, then the execution of the program will continue. If the condition is false, then the execution of the program will stop.

The verify command is used to check if the given condition is true or not. If the condition is true, then the execution of the program will continue. If the condition is false, then the execution of the program will not stop, but an error message will be displayed.

19
Q

What are the WebDriver supported Mobile Testing Drivers?

A
  1. AndroidDriver is used to test Android applications. It can be used on real devices or emulators.
  2. IPhoneDriver is used to test iOS applications. It can only be used on real devices.
  3. RemoteWebDriver is used to test web applications on mobile devices. It can be used with a variety of browsers, including Safari, Chrome, and Firefox.
  4. Selendroid is used to test Android applications. It can be used on real devices or emulators.
20
Q

What is the difference between “type” and “typeAndWait” command?

A

The “type” command is used to enter text into a field on a web page. The “typeAndWait” command also enters text into a field, but it waits for the page to load before proceeding to the next command. This can be useful if you are unsure whether or not the text you entered will cause the page to refresh.

The main difference between the “type” and “typeAndWait” command is that the “type” command does not wait for the page to reload, while the “typeAndWait” command does. If you are unsure whether or not the text you are entering will cause the page to refresh, it is best to use the “typeAndWait” command. This way, you can be sure that the next command will not be executed until the page has finished loading.

21
Q

What is the main disadvantage of implicit wait?

A

he main disadvantage of implicit wait is that it can slow down your tests. This is because, by default, the implicit wait time is set to zero. As such, if an element is not found immediately, your test will keep trying to find it for the duration of the implicit wait time. This can add a significant amount of time to your test suite. Another disadvantage of implicit wait is that it can cause your tests to fail if the element you are waiting for takes longer to appear than the implicit wait time. Finally, implicit wait can make your tests less reliable because they can introduce flakiness.