Advance Selenium Multiple Choice Questions – MCQ2

HOME








WebDriver driver = new ChromeDriver();
driver.get("https://www.example.com");
WebElement element = driver.findElement(By.id("submitButton"));
element.click();

WebDriver driver = new ChromeDriver();
driver.get("https://www.example.com");
List<WebElement> links = driver.findElements(By.tagName("a"));
System.out.println("Number of links: " + links.size());

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("elementId")));

driver.switchTo().___.accept();

WebElement dropdown = driver.findElement(By.id("dropdown"));
Select select = new Select(dropdown);
select.___("Option 1");

Actions actions = new Actions(driver);
WebElement element = driver.findElement(By.id("elementId"));
actions.contextClick(element).perform();

File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshot, new File("path/to/screenshot.png"));

driver.switchTo().___("frameNameOrId");

WebElement inputField = driver.findElement(By.id("inputField"));
inputField.sendKeys("test data");
inputField.sendKeys(Keys.TAB);

driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

WebElement table = driver.findElement(By.id("tableId"));
List<WebElement> rows = table.findElements(By.tagName("tr"));
WebElement firstCell = rows.get(0).findElements(By.tagName("td")).get(0);
System.out.println(firstCell.getText());

driver.manage().___();

Cookie cookie = new Cookie("name", "value");
driver.manage().___(cookie);

Select dropdown = new Select(driver.findElement(By.id("dropdownId")));
List<WebElement> options = dropdown.___();


try {
    WebElement element = driver.findElement(By.id("submit"));
    element.click();
} catch (NoSuchElementException e) {
    System.out.println("Element not found.");
}


Leave a comment