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();