121. Difference: Thread.sleep vs Implicit vs Explicit Wait
Type | Scope | Usage |
Thread.sleep | Static Wait | Sleeps for fixed time |
Implicit Wait | Applied globally | Waits for element existence |
Explicit Wait | Specific element | Waits for condition (clickable, visible, etc.) |
🔹 122. What is Fluent Wait in Selenium?
Fluent Wait is a type of Explicit Wait where:
- You define the maximum wait time
- Set polling frequency
- Ignore specific exceptions (like NoSuchElementException)
Example:
123. How to handle dropdown
Use Selenium’s Select class:
Select select = new Select(driver.findElement(By.id(“dropdownId”)));
select.selectByVisibleText(“Option1”);
124. List out all methods available in Select class
- selectByIndex(int index)
- selectByValue(String value)
- selectByVisibleText(String text)
- getOptions()
- getAllSelectedOptions()
- getFirstSelectedOption()
- deselectAll()
- deselectByIndex()
- deselectByValue()
- deselectByVisibleText()
125. How to capture all values from the dropdown
Select select = new Select(driver.findElement(By.id(“dropdown”)));
List<WebElement> allOptions = select.getOptions();
for(WebElement option : allOptions) {
System.out.println(option.getText());
}
126. How to capture only selected value from the dropdown
WebElement selectedOption = select.getFirstSelectedOption();
System.out.println(selectedOption.getText());
127. How to capture only non-selected values from the dropdown
List<WebElement> allOptions = select.getOptions();
List<WebElement> selectedOptions = select.getAllSelectedOptions();
allOptions.removeAll(selectedOptions);
128. How to work with multi-select dropdown
if (select.isMultiple()) {
select.selectByVisibleText(“Option1”);
select.selectByVisibleText(“Option2”);
}
129. How to select all similar values from the dropdown
List<WebElement> options = select.getOptions();
for (WebElement option : options) {
if (option.getText().contains(“testing”)) {
select.selectByVisibleText(option.getText());
}
}
130. How to work with custom select dropdown
Use Actions or JavaScriptExecutor for non-HTML select elements.
driver.findElement(By.xpath(“//input[@id=’autosuggest’]”)).sendKeys(“auto”);
Thread.sleep(1000);
driver.findElement(By.xpath(“//li[text()=’automation testing’]”)).click();
131. How to take mouse over operation on the element
Actions actions = new Actions(driver);
actions.moveToElement(driver.findElement(By.id(“menu”))).perform();
132. How to perform keyboard operation
Actions actions = new Actions(driver);
actions.sendKeys(Keys.ENTER).perform();
133. How to perform Ctrl+C
actions.keyDown(Keys.CONTROL).sendKeys(“c”).keyUp(Keys.CONTROL).perform();
134. Difference between build() & perform()
- build() creates a composite action
- perform() executes it
135. How to perform drag and drop
Actions actions = new Actions(driver);
actions.dragAndDrop(sourceElement, targetElement).perform();
136. How to perform right click operation
Actions actions = new Actions(driver);
actions.contextClick(driver.findElement(By.id(“element”))).perform();
Window Handling
137. How to work with new Tab or Browser window
String parent = driver.getWindowHandle();
Set<String> handles = driver.getWindowHandles();
for (String handle : handles) {
if (!handle.equals(parent)) {
driver.switchTo().window(handle);
}
}
138. How to work with GetWindowHandles()
Same as above.
139. How to handle Alert popup
Alert alert = driver.switchTo().alert();
alert.accept();
140. How to work with Calendar Pop-up
Use XPath to select a date element dynamically.