Selenium Flashcards
Explain the statement WebDriver driver = new ChromeDriver();
WebDriver is an interface provided by Selenium WebDriver & driver is a reference variable & equal to the assignment operator
Creating a reference variable of type WebDriver assigns the driver object to different browser specific drivers.
It allows multi browser testing by assigning the driver object to any of the desired browsers
Implicit wait
The implicit wait is a single line of code and can be declared in the setup method of the test script. The syntax and approach are simpler than explicit wait.
Include the above line of code into your test script soon after instantiation of WebDriver instance variable
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
The implicit wait mandates to pass two values as parameters. The first argument indicates the time in the numeric digits that the system needs to wait. The second argument indicates the time measurement scale
Explicit wait
Explicit waits are used to halt the execution until the time a particular condition is met or the maximum time has elapsed. Explicit waits are applied for a particular instance only.
WebDriverWait wait = new WebDriverWait(driver,30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(“//div[contains(text(),’COMPOSE’)]”)));
Explicit wait ExpectedConditions
- alert_is_present
- title_is
- element_to_be_clickable
- text_to_be_present_in_element
- element_to_be_selected
What is the use of Desired Capabilities?
Desired Capabilities is a class in Selenium used to set properties of browsers to perform cross browser testing of web applications.
Desired capabilities are used to set browser properties like browser name, browser version, path of browser driver in the system, what operating system to execute, etc.
What is DOM (document object model)?
The Document Object Model (DOM) is a programming interface for web documents. It represents the page so that programs can change the document structure, style, and content. The DOM represents the document as nodes and objects; that way, programming languages can interact with the page.
What is XPath & how it works (how it will find an element)?
XPath is a technique in Selenium to navigate through the HTML structure of a page. It will look for a given tag (text, attribute, etc.) Basically, XPath works based on the DOM structure
What is the difference between absolute & relative XPath?
- Absolute Xpath is the direct way to find the element, but the disadvantage of the absolute XPath is that if there are any changes made in the path of the element then that XPath gets failed.
The key characteristic of XPath is that it begins with the single forward slash(/), which means you can select the element from the root node. - Relative Xpath starts from the middle of HTML DOM structure. It starts with a double forward slash (//). It can search elements anywhere on the webpage, which means no need to write a long XPath and you can start from the middle of HTML DOM structure. Relative Xpath is always preferred as it is not a complete path from the root element.
What is the use of JavaScriptExecutor?
JavaScriptExecutor is an interface that is used to execute JavaScript with Selenium.
- To Click on a Button
- To Type Text in a Text Box without using sendKeys() method
- To refresh the browser window using Javascript
- To get the URL of a webpage
How to handle multiple windows in Selenium?
By using get window handles and then driver.switchTo().window(window id)
What is the difference between getWindowHandle() & getWindowHandles()?
getWindowHandle() returns the window handle of currently focused window/tab. getWindowHandles() returns all windows/tabs handles launched/opened by same driver instance including all parent and child window.
Return type of getWindowHandle() is String while return type of getWindowHandles() is Set<String>. The return type is Set as window handle is always unique</String>
How to find how many options are in the drop down menu?
We can extract all the options in a dropdown in Selenium with the help of Select class which has the getOptions() method. This retrieves all the options on a Select tag and returns a list of web elements. This method does not accept any arguments. And then use a size() method to have all the options
How to handle the mouse operations?
We use Actions class method which has several methods such as left click, right click, double click, move to element
What is the difference between hard assertion & soft assertion in TestNG?
- Hard Assertion throws AssertionError immediately when an Assert Condition fails and moves to next @Test method
- Soft Assert does not throw an exception when an Assert Condition fails and continues with the next step after the Assert Condition.
What is prioritization in TestNG?
In TestNG, Priority is an attribute that helps the users define the order in which they want the test cases to be executed. When you have multiple test cases and want them to run in a particular order, you can use the Priority attribute to set test priority in TestNG
Number 0 has the default (highest) priority
If we want to give a test method, priority higher than the default priority then we can simply assign a negative value to the priority attribute of that test method
@Test(priority = -1)