List of usage examples for org.openqa.selenium WebElement sendKeys
void sendKeys(CharSequence... keysToSend);
From source file:scormADL2004.java
License:Open Source License
public void switchLoginSession(int toLogin) { // To be safe and avoid Selenium Native click element, using submit wherever possible, to be fixed in 2.5.0 WebElement element; driver.switchTo().window("moodleWindow"); // Check if already logged in if (!isElementPresent(By.linkText("Login"))) { //driver.findElement(By.linkText("Logout")).click(); // Workaround for Selenium bug - 1020, to be fixed in 2.5.0 driver.findElement(By.linkText("Logout")).sendKeys(Keys.ENTER); wait.until(presenceOfElementLocated(By.linkText("SCORM 2004 ADL test course"))); driver.findElement(By.linkText("SCORM 2004 ADL test course")).click(); }/*from w w w .j a va2 s . c o m*/ if (toLogin != 2) { wait.until(presenceOfElementLocated(By.id("username"))); driver.findElement(By.id("username")).clear(); element = driver.findElement(By.id("password")); element.clear(); driver.findElement(By.id("username")).sendKeys(username1); element.sendKeys(password1); loginSession = 1; } else { wait.until(presenceOfElementLocated(By.id("username"))); driver.findElement(By.id("username")).clear(); element = driver.findElement(By.id("password")); driver.findElement(By.id("username")).sendKeys(username2); element.sendKeys(password2); loginSession = 2; } element.submit(); }
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();/* w ww . ja va2s . c o m*/ }
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 {//from ww w.j a v a2 s.c o m // 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 //Verify the filter functionality public void test2() throws Exception { //No need to WAIT, since we are running test in a fixed order, we know the DOM is ready (because of the wait in test1) WebElement element = driver.findElement(By.id("filter")); element.sendKeys("2002"); WebElement e = driver.findElement(By.tagName("tbody")); List<WebElement> rows = e.findElements(By.tagName("tr")); Assert.assertThat(rows.size(), is(2)); }
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();//from ww w . j a v a 2 s . c o m WebElement desc = driver.findElement(By.name("description")); desc.clear(); 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 test7() throws Exception { WebElement newCar = driver.findElement(By.id("new")); newCar.click();/* www .jav a 2 s .c o m*/ 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(); (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 lookUp2002() throws Exception { WebElement element = (new WebDriverWait(driver, WAIT_MAX)) .until((ExpectedCondition<WebElement>) (WebDriver d) -> { return driver.findElement(By.xpath("//*[@id=\"filter\"]")); });//from ww w .j av a 2 s .co m element.clear(); element.sendKeys("2002"); WebElement table = driver.findElement(By.tagName("tbody")); List<WebElement> rows = table.findElements(By.tagName("tr")); Assert.assertThat(rows.size(), is(2)); }
From source file:testTheClient.java
@Test public void removeFilterTest() throws Exception { WebElement element = driver.findElement(By.id("filter")); element.sendKeys(Keys.BACK_SPACE); WebElement tableBody = (new WebDriverWait(driver, WAIT_MAX)) .until((ExpectedCondition<WebElement>) (WebDriver d) -> { return d.findElement(By.tagName("tbody")); });/* w w w . ja v a2 s.co m*/ List<WebElement> rows = tableBody.findElements(By.tagName("tr")); Assert.assertThat(rows.size(), is(5)); }
From source file:testTheClient.java
@Test public void verifyAlterations() throws Exception { WebElement editButton = null;//from ww w . j a va2 s .c om List<WebElement> rows = (new WebDriverWait(driver, WAIT_MAX)) .until((ExpectedCondition<WebElement>) (WebDriver d) -> { return d.findElement(By.tagName("tbody")); }).findElements(By.tagName("tr")); ; for (int i = 0; i < rows.size(); i++) { if (rows.get(i).findElements(By.tagName("td")).get(0).getText().equalsIgnoreCase("938")) { editButton = rows.get(i); break; } } editButton = editButton.findElements(By.tagName("td")).get(7).findElements(By.tagName("a")).get(0); //click the edit button editButton.click(); //clear description field and type coolscars WebElement element = driver.findElement(By.id("description")); element.clear(); element.sendKeys("cool cars"); driver.findElement(By.xpath("//*[@id=\"save\"]")).click(); List<WebElement> updatedRows = (new WebDriverWait(driver, WAIT_MAX)) .until((ExpectedCondition<WebElement>) (WebDriver d) -> { return d.findElement(By.tagName("tbody")); }).findElements(By.tagName("tr")); ; String newDescr = null; for (int i = 0; i < updatedRows.size(); i++) { if (updatedRows.get(i).findElements(By.tagName("td")).get(0).getText().equalsIgnoreCase("938")) { newDescr = updatedRows.get(i).findElements(By.tagName("td")).get(5).getText(); break; } } assertThat(newDescr, is("cool cars")); }
From source file:openCloseTables.java
public static void main(String[] args) throws IOException { System.setProperty("webdriver.ie.driver", "C:\\Users\\Colin Cook\\Desktop\\selenium-2.53.1\\IEDriverServer.exe"); WebDriver driver = new InternetExplorerDriver(); driver.get("http://10.0.1.53/opstar_test/"); out.println("Launching Internet Explorer browser.."); driver.manage().window().maximize(); try {//from w w w . j av a2s. c o m Thread.sleep(3000); // pauses for 3 seconds } catch (InterruptedException e) { e.printStackTrace(); } out.println("The title of the page being tested is: " + driver.getTitle()); WebElement acknowledge = driver .findElement(By.xpath("html/body/div[5]/div[1]/div[2]/div[2]/div[1]/div/div[2]/center/a")); acknowledge.click(); //first popup when you go on site try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } WebElement applications = //driver.findElement(By.xpath("html/body/div[3]/div[2]/div/div[1]/ul[2]/li[5]/a/span")); driver.findElement(By.linkText("Applications")); applications.click(); WebElement toTools = driver .findElement(By.xpath("html/body/div[3]/div[2]/div/div[1]/ul[2]/li[7]/ul/li[2]/a")); toTools.click(); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } WebElement traingFolder = driver .findElement(By.xpath("html/body/div[3]/div[2]/div/div[1]/ul[2]/li[7]/ul/li[2]/ul/li/a")); traingFolder.click(); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } WebElement closeBox = driver.findElement(By.id("cboxClose")); closeBox.click(); //clicks second popup acknolwedge box try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } WebElement textBox = driver.findElement(By .xpath("html/body/div[3]/div[4]/div[2]/div/div[1]/div/div[2]/div/form/div/div/span/span[1]/span")); textBox.click(); textBox.sendKeys("ken"); //first three letters of someones name try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } textBox.sendKeys(Keys.ENTER); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } WebElement table1 = driver.findElement( By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[1]/div/div[1]/div/a[2]")); table1.click(); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } table1.click(); out.println("The Designations folder has been successfully opened and closed"); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } WebElement table2 = driver.findElement( By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[2]/div/div[1]/div/a[2]")); table2.click(); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } table2.click(); out.println("The Waivers folder has been successfully opened and closed"); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } WebElement table3 = driver.findElement( By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[3]/div/div[1]/div/a[2]")); table3.click(); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } table3.click(); out.println("The Professional Licenses/ Certificates / Medical folder has been opened and closed"); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } WebElement table4 = driver.findElement( By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[4]/div/div[1]/div/a[2]")); table4.click(); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } table4.click(); out.println("The First Aid folder has been succesfully opened and closed"); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } WebElement table5 = driver.findElement( By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[5]/div/div[1]/div/a[2]")); table5.click(); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } table5.click(); out.println("The Star folder has been successfully opened and closed"); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } WebElement table6 = driver.findElement( By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[6]/div/div[1]/div/a[2]")); table6.click(); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } table6.click(); out.println("The Training Courses and Tests folder has been successfully opened and closed"); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } WebElement table7 = driver.findElement( By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[7]/div/div[1]/div/a[2]")); table7.click(); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } table7.click(); out.println( "The Professional Development / Individual Development Plan folder has been successfully opened and closed"); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } WebElement table8 = driver.findElement( By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[8]/div/div[1]/div/a[2]")); table8.click(); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } table8.click(); out.println("The FLETC Certificates folder has been successfully opened and closed"); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } WebElement table9 = driver.findElement( By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[2]/div[9]/div/div[1]/div/a[2]")); table9.click(); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } table9.click(); out.println("The Miscellaneous folder has been succesfully opened and closed"); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } WebElement qualifications = driver .findElement(By.xpath("html/body/div[3]/div[4]/div[2]/div/div[2]/div[1]/div/div/div[1]/div/a[2]")); qualifications.click(); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } qualifications.click(); out.println("The Qualifications folder has been successfully opened and closed"); // I should program test scripts like this in the future // try { // WebElement xbox = driver.findElement(By.id("cboxClose")); // xbox.click(); // } catch(Exception e) { // System.err.print("NO NO NO that "); // } }