Element Handling in Selenium Part 3
Element Handling in Selenium Part 3
com)
4) Handling Link
System.setProperty("webdriver.chrome.driver", "E:/chromedriver.exe");
driver.get("https://www.google.com/");
//Check Link Existence
boolean linkPresent= driver.findElement(By.linkText("Gmail")).isDisplayed();
System.out.println(linkPresent);
//Click(Redirects)Link
driver.findElement(By.linkText("Gmail")).click();
Thread.sleep(2000);
driver.close();
}
}
driver.get("https://www.google.com/");
WebElement gmailLink = driver.findElement(By.linkText("Gmail"));
System.out.println(gmailLink.isDisplayed());
System.out.println(gmailLink.isEnabled());
System.out.println(gmailLink.getText());
gmailLink.click();
Thread.sleep(4000);
driver.close();
5) Handling Checkbox
Manual Actions:
- Select (Click)
- Unselect (Click)
driver.get("http://www.gcrit.com/build3/create_account.php");
driver.close();
6) Handling Button
Manual Actions:
- Click
driver.get("http://www.gmail.com");
boolean displayStatus =
driver.findElement(By.xpath("//*[@id='identifierNext']/content/span")).isDis
played();
System.out.println(displayStatus);
boolean enabledStatus =
driver.findElement(By.xpath("//*[@id='identifierNext']/content/span")).isEn
abled();
System.out.println(enabledStatus);
driver.findElement(By.xpath("//*[@id='identifierNext']/content/span")).click
();
7) Radio Button
Manual Actions:
- Select (Click)
driver.get("http://www.gcrit.com/build3/create_account.php");
System.out.println(displayStus);//true
System.out.println(enbledStatus);//true
System.out.println(selectedStatus);//false
driver.get("http://www.google.com");
driver.navigate().to("http://newtours.demoaut.com/");
//Click Image Button
driver.findElement(By.name("login")).click();
Thread.sleep(3000);
driver.navigate().to("https://www.seleniumhq.org/");
Thread.sleep(3000);
//Click Image Link
driver.findElement(By.xpath("//*[@id='choice']/tbody/tr/td[2]/center/a/img
")).click();
}
}
Manual Actions:
- Select an Item
- Return Items Count
driver.get("http://www.gcrit.com/build3/create_account.php?osCsid=6rqlkh
hibc3d4pvkdt6fafs4s1");
boolean displayStatus =
driver.findElement(By.name("country")).isDisplayed();
System.out.println(displayStatus);//true
boolean enabledStatus =
driver.findElement(By.name("country")).isEnabled();
System.out.println(enabledStatus);//true
dropdown.selectByVisibleText("India");
Thread.sleep(4000);