List of usage examples for org.openqa.selenium WebElement isSelected
boolean isSelected();
From source file:at.tugraz.ist.catroweb.admin.SendEmailNotificationTests.java
License:Open Source License
@Test(groups = { "functionality", "sendEmail" }, description = "select checkboxes one by one and by using select all checkbox") public void checkCheckboxes() throws Throwable { try {/*w w w.j a v a2s.co m*/ int checked = 0; openAdminLocation(); ajaxWait(); driver().findElement(By.id("aAdministrationTools")).click(); ajaxWait(); driver().findElement(By.id("aAdminToolsSendEmailNotification")).click(); ajaxWait(); assertTrue(isTextPresent(" (" + checked + " user(s) selected)")); List<WebElement> checkboxes = driver().findElements(By.className("chkBoxEmail")); for (WebElement checkbox : checkboxes) { assertFalse(checkbox.isSelected()); } for (WebElement checkbox : checkboxes) { driver().findElement(By.id(checkbox.getAttribute("id"))).click(); checked++; assertTrue(isTextPresent(" (" + checked + " user(s) selected)")); assertTrue(checkbox.isSelected()); } assertTrue(isTextPresent("unselect all")); // unselect all checkboxes by clicking on unselect all checkbox checked = 0; driver().findElement(By.id("chkboxSelectAll")).click(); ajaxWait(); for (WebElement checkbox : checkboxes) { assertFalse(checkbox.isSelected()); } assertTrue(isTextPresent("select all")); assertTrue(isTextPresent(" (" + checked + " user(s) selected)")); // select all checkboxes by clicking on select all checkbox driver().findElement(By.id("chkboxSelectAll")).click(); for (WebElement checkbox : checkboxes) { checked++; assertTrue(checkbox.isSelected()); } assertTrue(isTextPresent("unselect all")); assertTrue(isTextPresent(" (" + checked + " user(s) selected)")); } catch (AssertionError e) { captureScreen("SendEmailNotificationTests.checkCheckboxes"); throw e; } catch (Exception e) { captureScreen("SendEmailNotificationTests.checkCheckboxes"); throw e; } }
From source file:br.eti.kinoshita.selenium.util.Utils.java
License:Open Source License
/** * Select radio button//ww w . jav a 2 s . co m * * @param radioToClick */ public static void selectRadioButton(WebElement radioToClick) { for (int i = 0; i < 10; ++i) { radioToClick.click(); if (radioToClick.isSelected()) { break; } } }
From source file:br.ufmg.dcc.saotome.beholder.selenium.WebElementAdapter.java
License:Apache License
@Override public boolean isSelected() { return new StaleExceptionResolver<Boolean>() { @Override//from ww w .j a va 2 s.c o m public Boolean execute(WebElement element) { return element.isSelected(); } }.waitForElement(); }
From source file:ca.nrc.cadc.web.selenium.AbstractTestWebPage.java
License:Open Source License
protected void check(final WebElement element) throws Exception { if (element.isSelected()) { LOGGER.warn(String.format("Checkbox at %s is already checked.", element)); } else {//from w w w . jav a2s. c o m click(element); } }
From source file:ca.nrc.cadc.web.selenium.AbstractTestWebPage.java
License:Open Source License
protected void uncheck(final WebElement element) throws Exception { if (!element.isSelected()) { LOGGER.warn(String.format("Checkbox at %s is already unchecked.", element)); } else {/*w ww.j av a 2s . c o m*/ click(element); } }
From source file:chromedriveryahoologin.ChromeDriverDeleteTrashEmails.java
public static void main(String[] args) { try {//from w w w . j a v a2 s . c o m Integer pozSpam = 0; Integer pozTrash = 0; Integer pozHelp = 0; Integer pozCompose = 0; Integer pozNewFolder = 0; System.setProperty("webdriver.chrome.driver", "D:\\Proiecte\\selenium-java-2.47.1\\selenium-2.47.1\\chromedriver_win32\\chromedriver.exe"); System.setProperty("webdriver.chrome.logfile", "D:\\prjAutJava\\YahooLogin\\ChromeDriverDeleteSpam.log"); ChromeOptions options = new ChromeOptions(); options.addArguments("test-type"); options.addArguments("--start-maximized"); options.addArguments("--disable-web-security"); options.addArguments("--no-proxy-server"); options.addArguments("--disable-extensions"); options.addArguments("--disable-notifications"); options.addArguments("--disable-popup-blocking"); options.addArguments("--disable-plug-in"); Map<String, Object> prefs = new HashMap<String, Object>(); prefs.put("credentials_enable_service", false); prefs.put("profile.password_manager_enabled", false); options.setExperimentalOption("prefs", prefs); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(ChromeOptions.CAPABILITY, options); capabilities.setCapability(CapabilityType.SUPPORTS_APPLICATION_CACHE, true); capabilities.setCapability(CapabilityType.SUPPORTS_FINDING_BY_CSS, true); capabilities.setCapability(CapabilityType.SUPPORTS_LOCATION_CONTEXT, true); capabilities.setCapability(CapabilityType.SUPPORTS_ALERTS, true); capabilities.setCapability(CapabilityType.PLATFORM, "WIN10"); driver = new ChromeDriver(capabilities); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.get("https://mail.yahoo.com"); driver.manage().window().maximize(); WebElement usernameElem = driver.findElement(By.id("login-username")); usernameElem.sendKeys("andadeacu@yahoo.com"); WebElement Next = driver.findElement(By.name("signin")); Next.click(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); WebElement passwordElem = driver.findElement(By.xpath("//input[@id='login-passwd']")); boolean selected = passwordElem.isSelected(); CharSequence password = ""; passwordElem.sendKeys(password); WebElement login = driver.findElement(By.id("login-signin")); login.click(); driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); driver.switchTo().activeElement(); WebElement tooltipElem = driver.findElement(By.xpath("//div[@class='Pos(r) M(0) TooltipContent']")); List<WebElement> childs = tooltipElem.findElements(By.xpath("//ul/li")); for (int j = 0; j < childs.size(); j++) { WebElement spamElem = childs.get(j); /* * System.out.println("ancorele " + j + " " + " tag " + * childs.get(j).getTagName() + " " + childs.get(j).getText() + * " " + childs.get(j).getAttribute("innerHTML")); */ if (spamElem.getText().startsWith(("Spam"))) { pozSpam = j; } if (spamElem.getText().startsWith(("Help"))) { pozHelp = j; } if (spamElem.getText().startsWith(("Compose"))) { pozCompose = j; } if (spamElem.getText().startsWith(("New"))) { pozNewFolder = j; } if (spamElem.getText().startsWith(("Trash"))) { System.out.println(j + " Trash is " + spamElem.getTagName() + " " + spamElem.getText()); pozTrash = j; break; } } System.out.println(pozTrash); WebElement trashElem = childs.get(pozTrash); /* * System.out.println("trashElem " + trashElem.getTagName() + * " text " + trashElem.getText() + " class_atribute " + * trashElem.getAttribute("class") + " data_action " + * trashElem.getAttribute("data_action")); */ WebElement trashFolderEmpty = trashElem.findElement( By.xpath("//a[@class='x-gap btn btn-trash']/span/span[@class='btn icon icon-delete']")); /* * System.out.println("spamEmptyFolder " + * spamFolderEmpty.getTagName() + " text " + * spamFolderEmpty.getText() + " location " + * spamFolderEmpty.isEnabled()); */ trashFolderEmpty.click(); int timeOut = 5; WebDriverWait wait = new WebDriverWait(driver, timeOut); driver.switchTo().alert(); /* for Chrome is not working WebElement modalPopUp = driver.findElement(By .className("modal-hd yui3-widget-hd")); */ WebElement btnDeleteSpamEmails = driver.findElement(By.className("btn left right default")); /* * <button id="okayModalOverlay" class="btn left right default" * title="OK" role="button" data-action="ok">OK</button> */ btnDeleteSpamEmails.click(); driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); driver.switchTo().activeElement(); // verify msg after you delete spam emails System.out.println(driver.getCurrentUrl()); driver.quit(); } catch (Exception ex) { ex.printStackTrace(); driver.quit(); } }
From source file:cn.hxh.springside.test.functional.Selenium2.java
License:Apache License
/** * ?Element./*from www.j a va 2 s . c o m*/ */ public void uncheck(By by) { WebElement element = driver.findElement(by); if (element.isSelected()) { element.click(); } }
From source file:cn.hxh.springside.test.functional.Selenium2.java
License:Apache License
/** * Element?./*from w w w .j ava 2 s.com*/ */ public boolean isChecked(By by) { WebElement element = driver.findElement(by); return element.isSelected(); }
From source file:cn.newtouch.util.test.utils.SeleniumUtils.java
License:Apache License
/** * Selnium1.0.//from w w w . jav a 2 s. c o m */ public static void uncheck(WebElement element) { if (element.isSelected()) { element.toggle(); } }
From source file:co.edu.uniandes.csw.sport.master.test.SportMasterTest.java
/** * CreateUserSport-> Crea un nuevo User y le asocia varios elementos sport * /* www. java2s . c om*/ */ @Test public void createUserSport() throws Exception { Thread.sleep(2000); driver.get(baseUrl + "/sport.web/userMaster.html"); Thread.sleep(5000); driver.findElement(By.xpath("//button[contains(@id,'createButton')]")).click(); Thread.sleep(2000); driver.findElement(By.id("userName")).clear(); driver.findElement(By.id("userName")).sendKeys("nombre"); driver.findElement(By.id("firstName")).clear(); driver.findElement(By.id("firstName")).sendKeys("nombre1"); driver.findElement(By.id("lastName")).clear(); driver.findElement(By.id("lastName")).sendKeys("nombre2"); //HREF indicando el tab de detalle a seleccionar driver.findElement(By.xpath("//a[contains(@href,'sport')]")).click(); Thread.sleep(2000); driver.findElement(By.xpath("//button[contains(@id,'addButton')]")).click(); //Toma todos los webElement cuyo id sea "selection" y de tipo checkbox. List<WebElement> lst = driver .findElements(By.xpath("//input[contains(@id,'selection')][@type='checkbox']")); for (WebElement lst1 : lst) { if (!lst1.isSelected()) { lst1.click(); // Si no esta seleccionado hace click en el checkbox, agrega todos los deportes existentes } } driver.findElement(By.id("addButton")).click(); List<WebElement> tables = driver.findElement(By.xpath("//div[contains(@id,'sport')]")) .findElements(By.xpath("//table[contains(@class,'table striped')]/tbody/tr")); if (tables.size() != lst.size()) { fail(); } driver.findElement(By.xpath("//button[contains(@id,'saveButton')]")).click(); Thread.sleep(3000); List<WebElement> table = driver .findElements(By.xpath("//table[contains(@class,'table striped')]/tbody/tr")); boolean fail = false; for (WebElement webElement : table) { List<WebElement> elems = webElement.findElements(By.xpath("td")); if (elems.get(0).getText().equals("nombre") && elems.get(1).getText().equals("nombre1")) { fail = true; } } assertTrue(fail); }