Selenium Flashcards

1
Q

How many locators we have?

A

Selenium 3 has 8 locators namely ID, Name, class, XPath, CssSelectors, LinkText, PartialLinkText, and TagName which helps us to locate the web elements on DOM

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

What are the Selenium components?

A

Selenium IDE: plugin for browser
Selenium RC: old version of webdriver
Selenium WebDriver: automates testing by simulating user interactions
Selenium Grid: Proxy server that lets QA’s run tests in parallel.

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

What are best locators to use?

A

XPath, ID, and CSS

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

How to find all links on web page?

A

ListallLinks=driver.findElements(By.tagName(“a”));

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

What is the difference between partial link text and link text?

A

LinkText: it returns elements with an exact match of the given text

PartialLinkText returns elements which include the given text

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

How do you handle dynamic web elements?

A

With using xpath or css, and explicit waits or fluent waits.

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

What is a web element?

A

a WebElement in Selenium is essentially an HTML element on a website

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

What are the different types of Alerts?

A

Simple alert, just an OK button.

Confirmation alert, accept or dismiss

Promp alert, asks you to input something

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

How do we handle Alert?

A
  • driver.switchTo().alert().accept()
  • driver.switchTo().alert().dismiss()
  • driver.switchTo().alert().sendKeys()
  • driver.switchTo().alert().getText()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do we handle HTML based popups?

A

if its iframe then switch to it with driver.switchTo().frame(“iframe-id”);

else just get the element of it and do what you gotta do

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

How to handle the popups that appear randomly?

A

You can disable them completely by using ChromeOptions in selenium.

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

How to drag and drop the element?

A

By using the Actions class, and doing actions.dragAndDrop(sourceElement, targetElement).perform();

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

How to scroll down and scroll up?

A

actions.sendKeys(Keys.PAGE_DOWN).perform();
actions.sendKeys(Keys.PAGE_UP).perform();

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

What is perform method?

A

The perform method in Selenium WebDriver’s Actions class is used to execute a sequence of actions that you have built

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

What is difference between Actions and Action class?

A

Actions is a class and its what you make an object off to use actions.

Action is used to store a sequence of actions.

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

What is context click?

A

Its a right click dick

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

How to hover over?

A

actions.moveToElement(elementToHover).perform();

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

How to right click and double click?

A

actions.contextClick(elementToRightClick).perform();

actions.doubleClick(elementToDoubleClick).perform();

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

How to handle dropdowns?

A

By using the Select class and its methods.

20
Q

What is Select class in Selenium?

A

Its a part of selenium which lets you interact with a dropdown element on web pages.

21
Q

How to select the option in dropdown?

A

selectByVisibleText or ByValue or ByIndex

22
Q

How to get all the options in Dropdown?

A

List options = dropdown.getOptions();

23
Q

How to handle multiple windows in Selenium?

A

Store each windowhandle by using Driver.getWindowHandle, and switching to whichever one you need.

24
Q

How to switch between the windows?

A

driver.switchTo().window(windowhandle);

25
Q

How to get window ID?

A

driver.getWindowHandle();

26
Q

Difference between driver.get() and navigate().to()

A

navigate.to has history tracking so you can go back unlike driver.get, it allows you to manage browser navigation operations more flexibly.

27
Q

How do you download and upload file?

A

download you need to enable downloads with chromeoptions, then you can simply click the download button element

upload you sendkeys a string which contains a filepath to the file you want to upload

28
Q

Difference between radio button and check box?

A

Radio button you can only select one, checkbox you can select multiple. You can deselect a checkbox but you cannot deselect a radio without selecting another one first.

29
Q

How to check if checkbox is selected?

A

get the elemenet of the checkbox and to element.isSelected();

30
Q

How to achieve synchronization?

A

You can achieve synchronization by using implic wait, explicit wait, fluent wait, and hardcoded sleeps.

31
Q

What is difference between implicit and explicit wait?

A

Implicit wait applies globally, causing WebDriver to wait for a certain amount of time before throwing a NoSuchElementException Explicit wait, is applied to a specific element or condition, making WebDriver wait until a condition is met or a maximum time limit is reached.

32
Q

What is difference between fluent and explicit wait?

A

Fluent wait has more capabilities, such as specifying the polling frequency and ignoring specific exceptions during the wait period. Explicit wait waits for a specific condition to be met for a certain period without these additional configurations.

33
Q

What is thread.sleep?

A

Its a hardcoded wait provided by java, it pauses code execution.

34
Q

Difference between findElement and findElements?

A

FindElement returns one element with the specified locator, findElements can be used to find all elements that have the locator that you use

35
Q

Difference between driver.quit() and driver.close()?

A

driver.close(): Closes the current browser window that the WebDriver is controlling.

driver.quit(): Closes all the browser windows opened by the WebDriver and ends the WebDriver session.

36
Q

Difference between getText and getAttribute?

A

getText(): Retrieves the visible inner text of a web element. It returns the text content that is displayed on the web page.

getAttribute(String attributeName): Retrieves the value of a specified attribute of a web element. It can be used to get various attributes like id, name, class, href, value, etc.

37
Q

Difference between xpath and css selector?

A

XPath is more powerful and flexible, allowing for complex queries, while CSS Selectors are simpler, faster, and generally easier to read and maintain.

38
Q

How to move from parent to child and child to parent using xpath?

A

parent to child
//parent/child

child to parent
//child/parent

39
Q

Difference between absolute and relative xpath?

A

Absolute XPath specifies the full path from the root node

Relative XPath starts from any node and doesn’t require the full path

40
Q

What Selenium exceptions do you know?

A

NoSuchElementException
TimeoutException
UnhandledAlertException
ElementNotVisibleException
NoSuchWindowException

41
Q

How to handle exceptions?

A

You can handle exceptions by using javas try catch as its the same principle with exceptions as java

42
Q

How do you maximize the window?

A

driver.manage().window().maximize();

43
Q

What is the difference between maximize and fullscreen?

A

Maximizing a window adjusts its size to fill the screen while keeping UI elements visible. Fullscreen mode hides all UI elements, providing a distraction-free, immersive view.

44
Q

How do we get title of the page?

A

You can use driver.GetTitle(); and store it in a string or sout it.

45
Q

What is iframe in HTML?

A

an Iframe is an application inside an application, for example a youtube video embedded on a website or an ad.

46
Q

How to handle frames using Selenium?

A

You have to switch to it by using driver.switchTo().frame(id or index or name or WebElement) only then you can interact with it

47
Q

How do we handle web tables in Selenium?

A

You handle webtables in selenium like a regular element, there is thead which is header, tbody which is the whole table, tr which is row and td which is cell