Selenium Flashcards
How many locators we have?
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
What are the Selenium components?
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.
What are best locators to use?
XPath, ID, and CSS
How to find all links on web page?
List<WebElement>allLinks=driver.findElements(By.tagName("a"));</WebElement>
What is the difference between partial link text and link text?
LinkText: it returns elements with an exact match of the given text
PartialLinkText returns elements which include the given text
How do you handle dynamic web elements?
With using xpath or css, and explicit waits or fluent waits.
What is a web element?
a WebElement in Selenium is essentially an HTML element on a website
What are the different types of Alerts?
Simple alert, just an OK button.
Confirmation alert, accept or dismiss
Promp alert, asks you to input something
How do we handle Alert?
- driver.switchTo().alert().accept()
- driver.switchTo().alert().dismiss()
- driver.switchTo().alert().sendKeys()
- driver.switchTo().alert().getText()
How do we handle HTML based popups?
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 to handle the popups that appear randomly?
You can disable them completely by using ChromeOptions in selenium.
How to drag and drop the element?
By using the Actions class, and doing actions.dragAndDrop(sourceElement, targetElement).perform();
How to scroll down and scroll up?
actions.sendKeys(Keys.PAGE_DOWN).perform();
actions.sendKeys(Keys.PAGE_UP).perform();
What is perform method?
The perform method in Selenium WebDriver’s Actions class is used to execute a sequence of actions that you have built
What is difference between Actions and Action class?
Actions is a class and its what you make an object off to use actions.
Action is used to store a sequence of actions.
What is context click?
Its a right click dick
How to hover over?
actions.moveToElement(elementToHover).perform();
How to right click and double click?
actions.contextClick(elementToRightClick).perform();
actions.doubleClick(elementToDoubleClick).perform();
How to handle dropdowns?
By using the Select class and its methods.
What is Select class in Selenium?
Its a part of selenium which lets you interact with a dropdown element on web pages.
How to select the option in dropdown?
selectByVisibleText or ByValue or ByIndex
How to get all the options in Dropdown?
List<WebElement> options = dropdown.getOptions();</WebElement>
How to handle multiple windows in Selenium?
Store each windowhandle by using Driver.getWindowHandle, and switching to whichever one you need.
How to switch between the windows?
driver.switchTo().window(windowhandle);
How to get window ID?
driver.getWindowHandle();
Difference between driver.get() and navigate().to()
navigate.to has history tracking so you can go back unlike driver.get, it allows you to manage browser navigation operations more flexibly.
How do you download and upload file?
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
Difference between radio button and check box?
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.
How to check if checkbox is selected?
get the elemenet of the checkbox and to element.isSelected();
How to achieve synchronization?
You can achieve synchronization by using implic wait, explicit wait, fluent wait, and hardcoded sleeps.
What is difference between implicit and explicit wait?
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.
What is difference between fluent and explicit wait?
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.
What is thread.sleep?
Its a hardcoded wait provided by java, it pauses code execution.
Difference between findElement and findElements?
FindElement returns one element with the specified locator, findElements can be used to find all elements that have the locator that you use
Difference between driver.quit() and driver.close()?
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.
Difference between getText and getAttribute?
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.
Difference between xpath and css selector?
XPath is more powerful and flexible, allowing for complex queries, while CSS Selectors are simpler, faster, and generally easier to read and maintain.
How to move from parent to child and child to parent using xpath?
parent to child
//parent/child
child to parent
//child/parent
Difference between absolute and relative xpath?
Absolute XPath specifies the full path from the root node
Relative XPath starts from any node and doesn’t require the full path
What Selenium exceptions do you know?
NoSuchElementException
TimeoutException
UnhandledAlertException
ElementNotVisibleException
NoSuchWindowException
How to handle exceptions?
You can handle exceptions by using javas try catch as its the same principle with exceptions as java
How do you maximize the window?
driver.manage().window().maximize();
What is the difference between maximize and fullscreen?
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.
How do we get title of the page?
You can use driver.GetTitle(); and store it in a string or sout it.
What is iframe in HTML?
an Iframe is an application inside an application, for example a youtube video embedded on a website or an ad.
How to handle frames using Selenium?
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
How do we handle web tables in Selenium?
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