101. Difference between quit() & close() in Selenium
- driver.quit(): Closes all browser windows opened by Selenium and ends the WebDriver session.
- driver.close(): Closes only the current active browser window
๐น 102. How to Maximize & Minimize the Browser in Selenium WebDriver
// Maximize
driver.manage().window().maximize();
// Minimize
driver.manage().window().minimize();
๐น 103. What is WebDriver – Interface or Class?
WebDriver is an interface provided by Selenium that represents the core methods used to automate browsers. Classes like ChromeDriver, FirefoxDriver implement this interface.
๐น 104. What is the Super Interface of WebDriver?
The SearchContext interface is the super interface of WebDriver. It contains the basic methods: findElement() and findElements().
๐น 105. What is WebElement & Methods in Selenium?
WebElement represents HTML elements. It has several methods like:
- click()
- sendKeys()
- getText()
- getAttribute()
- isDisplayed()
- isEnabled()
- isSelected()
๐น 106. How Many Locators in Selenium? Which One is Preferred?
Selenium has 8 locators:
- id
- name
- className
- tagName
- linkText
- partialLinkText
- xpath
- cssSelector
Preferred: id for speed and reliability.
๐น 107. How to Check Whether Object is Present in GUI?
boolean isPresent = driver.findElements(By.id(“elementId”)).size() > 0;
๐น 108. How to Check Text from the UI?
String text = driver.findElement(By.id(“elementId”)).getText();
๐น 109. How to Capture Element Color, Height, Width, Font-size?
String color = element.getCssValue(“color”);
String height = element.getCssValue(“height”);
String width = element.getCssValue(“width”);
String fontSize = element.getCssValue(“font-size”);
๐น 110. How to Get the Location of a WebElement?
Point location = element.getLocation();
int x = location.getX();
int y = location.getY();
๐น 111. How to Check if Object is Selected?
boolean selected = element.isSelected();
๐น 112. How to Check if Object is Enabled?
boolean enabled = element.isEnabled();
๐น 113. How to Delete All Cookies in WebDriver?
driver.manage().deleteAllCookies();
๐น 114. Do We Use Constructors in WebDriver?
No. We donโt define custom constructors in WebDriver usage. But internally, the driver classes like ChromeDriver have constructors.
๐น 115. How to Compare Two Images in Selenium?
Use OpenCV, Sikuli, or BufferedImage class in Java for pixel-by-pixel image comparison.
๐น 116. How to Get WebElement Height and Width?
Dimension size = element.getSize();
int height = size.getHeight();
int width = size.getWidth();
๐น 117. What is Synchronization in Selenium?
Synchronization is the process of matching the execution speed of Selenium with the applicationโs load time. It avoids ElementNotVisibleException.
๐น 118. How to Handle Synchronization in Selenium?
Using different wait mechanisms:
- Implicit Wait
- Explicit Wait
- Fluent Wait
- Thread.sleep (not recommended)
๐น 119. Which Wait is Used for Page Load?
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
๐น 120. How to Handle Dynamic Objects?
Strategies:
- Use dynamic XPath
- Wait for element visibility
- Use contains(), starts-with() functions
๐The Next 20 Questions-IV: AUTOMATION TESTING
๐The Next 15 Questions-V: AUTOMATION TESTING