List of usage examples for org.openqa.selenium WebElement click
void click();
From source file:DesktopChosenIT.java
License:Apache License
protected void openDropDown() { WebElement btn; if (isMultipleChosenComponent()) { btn = getInput();/*from w ww . j av a 2 s.com*/ } else { // single String xpath = "//div[@id='chosen_container__0_chzn']"; btn = webDriverWait().until(elementToBeClickable(By.xpath(xpath))); } btn.click(); }
From source file:DesktopChosenIT.java
License:Apache License
/** * Deselect an option previously selected. Work only with multiple chosen list box. */// w ww .j a v a 2 s . c om private <T extends Enum<T>> void deselectOption(T val, Renderer<T> renderer) { String xpath = String.format("//li[span/text()='%s']/a", renderer.render(val)); WebElement abbr = webDriverWait().until(presenceOfElementLocated(By.xpath(xpath))); abbr.click(); }
From source file:scormADL2004.java
License:Open Source License
public void launchTestPackage(String testPackageName) { // Check to see which user should launch the package. checkLoginSession();/*from w w w . ja v a 2s . c om*/ driver.switchTo().window("moodleWindow"); wait.until(presenceOfElementLocated(By.xpath("//*[contains(.,'Recent activity')]"))); if (testPackageName.equalsIgnoreCase("DDM")) { driver.findElement(By.partialLinkText(testPackageName + "a SCORM package")).sendKeys(Keys.ENTER); } else { driver.findElement(By.partialLinkText(testPackageName + " SCORM package")).sendKeys(Keys.ENTER); } // Workaround for WebDriver bug, Seleniu, IE. wait.until(presenceOfElementLocated(By.id("page-footer"))); // Refresh Driver to crawl page again. driver.switchTo().window("moodleWindow"); if (isElementPresent(By.id("n"))) { WebElement element = driver.findElement(By.id("n")); element.click(); element.submit(); //driver.findElement(By.xpath("//input[@value='Enter']")).click(); } }
From source file:TestaCaixaDeEntrada.java
@Test(groups = "login") public void testaLoginSiapcon() throws Exception { driver.navigate().to("http://52.1.49.37/SIAPCON_SPRINT1" + sprintNumber); driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS); DefaultThrowTreatment def = new DefaultThrowTreatment(); // verifica se os elementos existem def.verifyElementPresenceById(driver, "RichWidgets_wt33:wtMainContent:wtUserNameInput"); def.verifyElementPresenceById(driver, "RichWidgets_wt33:wtMainContent:wtPasswordInput"); def.verifyElementPresenceById(driver, "RichWidgets_wt33:wtMainContent:wtLoginButton"); // caso exista escreve WebElement inputUser = driver.findElement(By.id("RichWidgets_wt33:wtMainContent:wtUserNameInput")); WebElement inputPasswd = driver.findElement(By.id("RichWidgets_wt33:wtMainContent:wtPasswordInput")); WebElement buttonLogin = driver.findElement(By.id("RichWidgets_wt33:wtMainContent:wtLoginButton")); // escreve as informaes= inputUser.sendKeys("claudiana.coelho"); inputPasswd.sendKeys("123456"); // clica no boto buttonLogin.click(); }
From source file:TestaCaixaDeEntrada.java
@Test(dependsOnGroups = "login", groups = "irpara") public void testaIrPara() throws Exception { driver.navigate().to("http://52.1.49.37/SIAPCON_SPRINT1" + sprintNumber + "/ListarProcessos.jsf?(Not.Licensed.For.Production)="); try {// ww w .j a v a 2 s . c om // div que contm a pgina atual e o total de pginas WebElement divPagination = driver .findElement(By.id("RichWidgets_wt88:wtMainContent:wtpaginacaoWidget:wtdivPagina")); // string separadora da contagem de pgina String pageSeparator = "/"; // ndice da String separadora da contagem de pgina Integer separatorPosition = divPagination.getText().indexOf(pageSeparator); // forma a string com o total de pginas na Caixa de Entrada String totalPaginas = divPagination.getText().substring(separatorPosition + 1, divPagination.getText().length()); // gera um inteiro dentro do intervalo de pginas que h Random number = new Random(); Integer validPage = number.nextInt(Integer.parseInt(totalPaginas)); if (validPage == 0) { validPage++; } // escreve o inteiro no input de paginao WebElement paginationInput = driver .findElement(By.id("RichWidgets_wt88:wtMainContent:wtpaginacaoWidget:wtirParaPaginaWidget")); paginationInput.clear(); paginationInput.sendKeys(validPage.toString()); // clica no boto ir para WebElement btnIrPara = driver .findElement(By.id("RichWidgets_wt88:wtMainContent:wtpaginacaoWidget:wt7")); btnIrPara.click(); // D um tempo para as requisies Ajax terminarem em milisec impedindo o Selenium de prosseguir // Para o DOM terminar de ser recarregado Thread.sleep(60000); // div que contm a pgina atual e o total de pginas divPagination = driver .findElement(By.id("RichWidgets_wt88:wtMainContent:wtpaginacaoWidget:wtdivPagina")); // forma a string com a pgina atual // Pega tudo at a barra pra depois remover o que no nmero totalPaginas = divPagination.getText().substring(0, separatorPosition + 1); // remove os espaos totalPaginas = totalPaginas.replaceAll(" ", ""); // remove as barras totalPaginas = totalPaginas.replaceAll("/", ""); // remove os caracteres no numricos totalPaginas = totalPaginas.replaceAll("[^0-9]", ""); // compara com a pgina que foi setada no input if (!(validPage == Integer.parseInt(totalPaginas))) { Assert.fail("Nmero da pgina atual no o mesmo setado no input de navegao de pginas"); } } catch (Exception e) { throw (e); } }
From source file:CarTest1.java
@Test public void test4() throws Exception { WebElement element = driver.findElement(By.id("h_year")); element.click(); int firstRow = driver.findElements(By.xpath("//tbody/tr[1 and td = '938']")).size(); int secondRow = driver.findElements(By.xpath("//tbody/tr[5 and td = '940']")).size(); System.out.println(driver.findElements(By.xpath("//tbody/tr[5 and td = '940']"))); Assert.assertThat(firstRow, is(1));/* ww w. j av a 2s. c om*/ Assert.assertThat(secondRow, is(1)); }
From source file:CarTest1.java
@Test public void test5() throws Exception { WebElement row = driver.findElement(By.xpath("//tbody/tr[td='938']")); WebElement a = row.findElements(By.tagName("a")).get(0); a.click(); WebElement desc = driver.findElement(By.name("description")); desc.clear();/*from w w w .jav a2 s. c o m*/ desc.sendKeys("Cool car"); WebElement submit = driver.findElement(By.id("save")); submit.click(); (new WebDriverWait(driver, WAIT_MAX)).until((ExpectedCondition<Boolean>) (WebDriver d) -> { WebElement newRow = d.findElement(By.xpath("//tbody/tr[td = '938']")); String b = newRow.findElements(By.tagName("td")).get(5).getText(); Assert.assertEquals("Cool car", b); return true; }); }
From source file:CarTest1.java
@Test public void test6() throws Exception { WebElement newCar = driver.findElement(By.id("new")); newCar.click(); WebElement submit = driver.findElement(By.id("save")); submit.click();//from w w w .j av a2 s.c om WebElement e = driver.findElement(By.tagName("tbody")); List<WebElement> rows = e.findElements(By.tagName("tr")); Assert.assertTrue(driver.findElement(By.id("submiterr")).isDisplayed()); Assert.assertEquals("All fields are required", driver.findElement(By.id("submiterr")).getText()); Assert.assertThat(rows.size(), is(5)); }
From source file:CarTest1.java
@Test public void test7() throws Exception { WebElement newCar = driver.findElement(By.id("new")); newCar.click(); WebElement year = driver.findElement(By.name("year")); WebElement reg = driver.findElement(By.name("registered")); WebElement make = driver.findElement(By.name("make")); WebElement model = driver.findElement(By.name("model")); WebElement desc = driver.findElement(By.name("description")); WebElement price = driver.findElement(By.name("price")); WebElement submit = driver.findElement(By.id("save")); year.sendKeys("2008"); reg.sendKeys("2002-5-5"); make.sendKeys("Kia"); model.sendKeys("Rio"); desc.sendKeys("As new"); price.sendKeys("31000"); submit.click();/*from w ww . j a v a 2 s . c om*/ (new WebDriverWait(driver, WAIT_MAX)).until((ExpectedCondition<Boolean>) (WebDriver d) -> { WebElement e = d.findElement(By.tagName("tbody")); List<WebElement> rows = e.findElements(By.tagName("tr")); Assert.assertThat(rows.size(), is(6)); return true; }); }
From source file:testTheClient.java
@Test public void sortByYear() { WebElement sort = (new WebDriverWait(driver, WAIT_MAX)) .until((ExpectedCondition<WebElement>) (WebDriver d) -> { return driver.findElement(By.xpath("//*[@id=\"h_year\"]")); });/* ww w.j a v a2 s .com*/ sort.click(); WebElement table = driver.findElement(By.tagName("tbody")); List<WebElement> sortedRows = table.findElements(By.tagName("tr")); Assert.assertThat(sortedRows.get(0).findElements(By.tagName("td")).get(0).getText(), is("938")); Assert.assertThat(sortedRows.get(4).findElements(By.tagName("td")).get(0).getText(), is("940")); }