Selenium Flashcards
How many changes do you need to make to manage your Selenium scripts? How do you maintain your test scripts and how frequently do you have to modify them?
It all depends on the types of changes. As an example, in our Page Object Model (POM) design, if a web element changes, we only update that specific element in its page class but, if there’s a change in existing functionality, we update the relevant functions. When we find new changes leading to test failures, then we update our test scripts.
What have you done to improve the performance of the selenium framework?
We created reusable elements, wrote efficient functions with clear steps, followed coding standards, wrote locators to handle dynamic elements, and provided data in external files such as Excel, Text files, and property files.
What is Selenium? Why do you prefer the Selenium Automation Tool? What are the common test automation tools? What are the testing types that can be supported by Selenium? Challenges, issues and limitations of Selenium?
Selenium is a set of open-source tools for automating web browsers, commonly used for functional and regression test automation across different operating systems (Windows, Linux, Macintosh). It supports various browsers like Mozilla Firefox, Internet Explorer, Google Chrome, Safari, and Opera. Selenium also provides compatibility with multiple programming languages, including Java, C#, Python, Perl, Ruby, PHP, and JavaScript. While Selenium and QTP are widely used, there are scenarios where Selenium WebDriver may not be suitable, including challenges in automating Captcha, reading barcodes, handling Windows-based pop-ups, image validation and comparison, and PDF validation and comparison
What is Selenium IDE? What is Selenium RC? What is Selenium Grid? When do you use Selenium Grid? What are the advantages of Selenium Grid? Which version of Selenium Webdriver are you using?
Selenium IDE is a Firefox plugin, Selenium RC (Selenium 1) is Selenium Remote Control, Selenium WebDriver (Selenium 2) is a browser automation framework using browser-specific drivers, and Selenium Grid is a tool for parallel test execution on multiple platforms. The advantages of Selenium Grid include the ability to run test cases in parallel, conduct multi-browser testing, and execute test cases on multiple platforms concurrently. Currently using Selenium 3.0 due to compatibility, a Maven project aids in easily updating dependencies through the pom.xml file.
What are the types of WebDriver APIs available in Selenium? Which WebDriver implementation claims to be the fastest? What is the super interface of WebDriver? What is a headless browser?
The webdriver APIs in Selenium include Gecko Driver, InternetExplorer Driver, Chrome Driver, Safari Driver, HTMLUnit Driver. HTMLUnitDriver fastest because it is headless browser which have less User Interface, the Super interface of WebDriver is SearchContext Interface.
What are the Locators available in Selenium? Which locator do you prefer?
There are eight locators in Selenium for identifying WebElements on a webpage: ID, ClassName, Name, TagName, LinkText, PartialLinkText, XPath, and CSS Selector. The choice of locator preference depends on the specific requirements and characteristics of the project.
What is an XPath? What is the difference between Absolute Path and Relative Path? What is the difference between “/” and “//”? In which situations are you going to use Xpath?
XPath is a tool in Selenium for locating elements, offering two types: Absolute XPath, using a single slash “/”, starting from the document node, and Relative XPath, using double slashes “//,” beginning selection from anywhere within the document. For example, an Absolute XPath could be “/html/body/td/tr/div[1]/div[2],” while a Relative XPath might be “//input[@id=’username’].”
How to launch a browser using Selenium WebDriver? Explain the line of code
// set the property for chrome driver, specify its location via the webdriver.chrome.driver -> System.setProperty(“we driv-er.chrome.driver”, driverPath + “chromedriver.exe”); // instantiate an instance of ChromeDriver, which will be driving our browser: -> public static WebDriver driver = new ChromeDriver(); // navigate to the specific url -> driver.get(“http://google.com”); To launch a Chrome browser with Selenium WebDriver, this code sets the ChromeDriver’s location, creates a ChromeDriver instance, and navigates to “http://google.com”.
Write a complex xpath or css expression? Which one is better? What is the difference?
XPath:”//label[@for=’personal_txtLicExpDate’]/following-sibling::img” CSS: “input[name^=’pass’]” Both CSS and XPath are valuable in Selenium automation. CSS selectors are often better for Internet Explorer, while XPath is generally preferred for other browsers like Firefox, Chrome, and Safari. Differences: CSS is generally more user-friendly and readable than XPath. CSS operates only in a forward direction, while XPath allows searching elements backward or forward. XPath can work with text, a capability not present in CSS. In terms of speed, CSS and XPath are generally comparable, but CSS is often noticeably faster than XPath in Internet Explorer, based on practical experiences.
What is the alternative to driver.get() method to open a URL using Selenium WebDriver? What is the difference?
To open a URL in Selenium WebDriver, we can use either driver.get(url) or driver.navigate().to(url). The difference is driver.get(url) directly opens the URL and waits for the page to load, but driver.navigate().to(url) provides more navigation control without waiting for the page to load immediately.
What is the difference between driver.close() and driver.quit() methods?
close() - It is used to close the browser or page which is currently having the focus. quit() - It is used to shut down the web driver instance or destroy the webdriver instance (Close all the windows).
How to get the text of a web element? How to get an attribute value using Selenium WebDriver?
To get the text of a web element using Selenium WebDriver, we can use the getText() method, and to retrieve the value of an attribute, or we can use the getAttribute(attributeName) method. String buttonText =driver.findElement(By.cssSelector(“div.success”)).getText();StringinnerText=driver.findElement(By.cssSelector(“div.success”)).getAttribute(“type”);
What is the difference between driver.findElement() and driver.findElements() commands? What is the return type of findElements?
findElement() will return only a single WebElement and if that element is not located or we use some wrong selector then it will throw NoSuchElementexception. findElements() will return List of WebElements – It returns an empty list, when an element is not found on the current page as per the given element locator mechanism. It doesn’t throws NoSuchElementException
How do you work with radio buttons which do not have an id attribute?
We can use click(), if “id” is not present we can use xpath (i.e you can use relative or absolute), css or other locator types. Also when there is a group of Radio Buttons/Check Boxes on the page then, their names may be the same, but values are different. In that case, we can use the Webdriver findElements command to get the list of web elements and then loop through them.
How do you handle an element in different windows? GetWindowHandle vs GetWindowHandles and the return types. Write a method to switch to the window based on title?
We can handle multiple windows in selenium webdriver using Switch To methods which will allow us to switch control from one window to another window. When we open the browser window and then 3 tabs pop open, selenium is focused on the first window. getWindowHandle() will get the handle of the page the webDriver is currently controlling. Every time Selenium opens a browser, it’s going to give an index ID for the page called handle. This handle is a unique identifier for the web page. This is different every time you open a page even if it is the same URL. String handle = driver.getWindowHandle(); getWindowHan-dles() method or command returns all handles from all opened browsers by Selenium WebDriver during execution Set<String> handleSet = driver.getWindowHandles(); //Returns a set of window handles You can use SwitchTo().Window("handle") to switch to the window you desire. You can use Switch-To().Window("mywindowID"), if you know the window ID. SwitchTo().Window("") will always go back to the base/main window. Method to switch to a window based on title public switchToWindow(String titleName) { driv-er.switchTo().window(titleName); //titleName = windowName }</String>
How to select a value in a dropdown? How to check the multiple selected value in a dropdown?
We can use the Select class to interact with dropdowns in Selenium WebDriver, providing methods such as selectByVisibleText(), selectByIndex(), and selectByValue() for different selection options. Additionally, the isMultiple() method helps verify if the dropdown allows multiple selections, allowing conditional handling based on its behavior.