0% found this document useful (0 votes)
15 views3 pages

Attributes

The document outlines various Selenium WebDriver operations including interacting with dropdowns, checkboxes, radio buttons, tables, images, capturing screenshots, date pickers, file uploads, and downloads. It provides specific code snippets for each operation, demonstrating how to navigate to web pages and perform actions on web elements. The examples include selecting options, clicking elements, retrieving text, and handling file operations on specified URLs.

Uploaded by

Ch Zaid kumboh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Attributes

The document outlines various Selenium WebDriver operations including interacting with dropdowns, checkboxes, radio buttons, tables, images, capturing screenshots, date pickers, file uploads, and downloads. It provides specific code snippets for each operation, demonstrating how to navigate to web pages and perform actions on web elements. The examples include selecting options, clicking elements, retrieving text, and handling file operations on specified URLs.

Uploaded by

Ch Zaid kumboh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

// DropDowns -----------------------

driver.get("https://the-internet.herokuapp.com/dropdown");
Select dropdown = new Select(driver.findElement(By.id("dropdown")));

dropdown.selectByVisibleText("Option 1");

dropdown.selectByValue("2");

dropdown.selectByIndex(1);

// Check Boxes -----------------------

driver.get("https://the-internet.herokuapp.com/checkboxes");

WebElement checkbox1 = driver.findElement(By.xpath("//input[1]"));


if (!checkbox1.isSelected())
{
checkbox1.click();
}

WebElement checkbox2 = driver.findElement(By.xpath("//input[2]"));


checkbox2.click();

// Radio Buttons -----------------------

driver.get("https://demo.guru99.com/test/radio.html");

WebElement radioButton = driver.findElement(By.id("vfb-7-1"));


radioButton.click();

System.out.println("Radio Button Selected: " + radioButton.isSelected());

// Tables -----------------------

driver.get("https://the-internet.herokuapp.com/tables");

List<WebElement> rows =
driver.findElements(By.xpath("//table[@id='table1']"));
for (WebElement row : rows)
{
List<WebElement> cells = row.findElements(By.tagName("td"));
for (WebElement cell : cells)
{
System.out.println(cell.getText());
}
}

// Images -----------------------

driver.get("https://demo.guru99.com/test/newtours/");

WebElement image = driver.findElement(By.xpath("//img[@alt='Mercury


Tours']"));
if (image.isDisplayed())
{
System.out.println("Image is Displayed :)");
}
System.out.println("Image Source : " + image.getAttribute("src"));

// Capture Screenshots -----------------------

driver.get("https://the-internet.herokuapp.com/");

// Full-Page Screenshot
File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileHandler.copy(screenshot, new
File("src/main/resources/Screenshots/screenshot.png"));

// Element screenshot
WebElement logo = driver.findElement(By.xpath("//h1"));

File logoScreenshot = logo.getScreenshotAs(OutputType.FILE);

FileHandler.copy(logoScreenshot, new
File("src/main/resources/Screenshots/logo-screenshot.png"));

// Date Pickers -----------------------

driver.get("https://jqueryui.com/datepicker/");

driver.switchTo().frame(driver.findElement(By.className("demo-frame")));

WebElement dateField = driver.findElement(By.id("datepicker"));


dateField.click();

WebElement dateToSelect = driver.findElement(By.xpath("//a[text()='25']"));


dateToSelect.click();

// File Upload -----------------------


driver.get("https://the-internet.herokuapp.com/upload");

WebElement fileInput = driver.findElement(By.xpath("//input[@id='file-


upload']"));
File file = new File("src/main/resources/Screenshots/screenshot.png");

fileInput.sendKeys(file.getAbsolutePath());

// File Download -----------------------

driver.get("https://the-internet.herokuapp.com/download");

WebElement fileLink = driver.findElement(By.linkText("test_upload.txt"));


fileLink.click();

You might also like