Q.41. What are some common conditions we can wait for using Explicit Wait in Selenium?
A: Here are a few commonly used expected conditions:
- elementToBeClickable()
- visibilityOfElementLocated()
- attributeContains()
- alertIsPresent()
- titleContains()
- titleIs()
- textToBePresentInElementLocated()
Q.42. What is Fluent Wait in Selenium?
A: Fluent Wait is like an advanced wait where you set a total wait time and also how often to check for the condition. It keeps checking at regular intervals until timeout or success.
Q.43. What keyboard actions can we do in Selenium?
A: Selenium can perform these keyboard actions:
- .sendKeys() – to type text
- .pressKey() – to press special keys (e.g., Ctrl, Enter)
- .releaseKey() – to release special keys
Q.44. What mouse actions are supported in Selenium?
A: Selenium supports:
- Click
- Double click
- Right click
- Mouse hover (move to element)
- Drag and drop
Q.45. How to perform a double click using Selenium?
A:
java
Actions action = new Actions(driver);
action.doubleClick(driver.findElement(By.id(“elementId”))).perform();
Q.46. How to right-click on an element?
A:
java
Actions action = new Actions(driver);
action.contextClick(driver.findElement(By.id(“elementId”))).perform();
Q.47. How to do mouse hover on an element?
A:
java
Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.id(“elementId”))).perform();
Q.48. How to get the current page URL?
A:
java
String url = driver.getCurrentUrl();
Q.49. How to get the title of the current web page?
A:
java
String title = driver.getTitle();
Q.50. How to get the page source (HTML code)?
A:
java
String pageSource = driver.getPageSource();
Q.51. How to check the tooltip of an element in Selenium?
A: Tooltips are usually in the title attribute.
java
String tooltip = driver.findElement(By.id(“elementId”)).getAttribute(“title”);
Q.52. How to find a link using its text?
A:
java
driver.findElement(By.linkText(“Full Link Text”));
driver.findElement(By.partialLinkText(“Partial Text”));
Q.53. What is DesiredCapabilities in Selenium?
A: DesiredCapabilities let you define browser-specific settings like browser type, version, and platform before launching it.
Q.54. How to find all links on a webpage?
A: All links are <a> tags. You can use:
java
List<WebElement> links = driver.findElements(By.tagName(“a”));
Q.55. What are some common Selenium exceptions?
A:
- NoSuchElementException
- ElementNotVisibleException
- NoAlertPresentException
- NoSuchFrameException
- NoSuchWindowException
- TimeoutException
- InvalidElementStateException
- NoSuchAttributeException
- WebDriverException
Q.56. How to take a screenshot using Selenium?
A:
java
File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshot, new File(“screenshot.png”));
Q.57. How to handle dropdowns in Selenium?
A:
java
Select dropdown = new Select(driver.findElement(By.id(“dropdownId”)));
dropdown.selectByVisibleText(“Option Text”);
dropdown.selectByValue(“optionValue”);
dropdown.selectByIndex(1);
Q.58. How to check which dropdown option is selected?
A:
java
CopyEdit
WebElement option = dropdown.getFirstSelectedOption();
System.out.println(option.getText());
Q.59. How to check if an element is visible on the page?
A:
java
boolean isVisible = driver.findElement(By.id(“elementId”)).isDisplayed();
Q.60. How to check if an element is enabled (clickable)?
A:
java
boolean isEnabled = driver.findElement(By.id(“elementId”)).isEnabled();