List of usage examples for org.openqa.selenium WebElement clear
void clear();
From source file:com.moodle.testmanager.pageObjectModel.ForumPosts.java
License:GNU General Public License
/** * Enter a value for subject//from w w w .j a v a 2 s. co m * @param subject The value for subject is passed fromthe test. */ public void enterSubjectField(String subject) { WebElement subjectField = driver.findElement(By.xpath(".//input[@id='id_subject']")); subjectField.clear(); subjectField.sendKeys(subject); }
From source file:com.moodle.testmanager.pageObjectModel.ForumSplit.java
License:GNU General Public License
/** * Enters a discussion name.//from ww w.jav a 2 s .c o m * @param name The desired name of the discussion to be passed from the test. */ public void enterDiscussionName(String name) { WebElement discussionName = driver.findElement( By.xpath(".//tr[contains(.,'" + this.properties.get("fieldLabel") + "')]/*/input[@type='text']")); discussionName.clear(); discussionName.sendKeys(name); }
From source file:com.mroza.seleniumTests.NewProgramsViewTests.NewProgramsViewPage.java
License:Open Source License
public void setAddProgramFields(String symbol, String name, String description) { WebElement symbolInputField = getInputFieldNamed(Utils.getMsgFromResources("newProgramsView.symbol")); symbolInputField.clear(); symbolInputField.sendKeys(symbol);/*from ww w.ja v a 2 s . c o m*/ WebElement nameInputField = getInputFieldNamed(Utils.getMsgFromResources("newProgramsView.name")); nameInputField.clear(); nameInputField.sendKeys(name); WebElement descriptionInputField = getTextAreaNamed( Utils.getMsgFromResources("newProgramsView.description")); descriptionInputField.clear(); descriptionInputField.sendKeys(description); }
From source file:com.mycompany.firstmavenproject.command.ClearCommand.java
@Override public void execute(Object driverObject) { WebElement we = (WebElement) driverObject; we.clear(); }
From source file:com.mycompany.selenium.SeleniumTests.java
@Test public void test2() throws Exception { WebElement element = driver.findElement(By.id("filter")); 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:com.mycompany.seleniumtest.Selenium2Example.java
public static void main(String[] args) { // Create a new instance of the Firefox driver // Notice that the remainder of the code relies on the interface, // not the implementation. System.setProperty("webdriver.chrome.driver", "/Users/CosticaTeodor/Downloads/drivers/chromedriver"); System.setProperty("webdriver.safari.driver", "/usr/bin/safaridriver"); //WebDriver driver = new ChromeDriver(); WebDriver driver = new ChromeDriver(); // And now use this to visit the cars program driver.get("http://localhost:3000/"); // Alternatively the same thing can be done like this // driver.navigate().to("http://www.google.com"); //verify the page is loaded, wait 10 seconds if it doesn't try {/*from w ww . j a va 2 s.co m*/ driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS); System.out.println("Page loaded!"); } catch (Exception e) { System.err.println(e.getMessage()); System.err.println(e.getStackTrace()); } int rowCount = driver.findElements(By.xpath("//table[@class='table']/tbody/tr")).size(); if (rowCount == 5) { System.out.println(rowCount + " is the row count!"); } else { System.out.println("rowcount should be different!"); } // Find the filter input element by its name WebElement searchFilter = driver.findElement(By.id("filter")); // Enter 2002 to search for searchFilter.sendKeys("2002"); //check if there are two rows left rowCount = driver.findElements(By.xpath("//table[@class='table']/tbody/tr")).size(); System.out.println("Row count after filter is: " + rowCount); searchFilter.clear(); searchFilter.sendKeys(""); rowCount = driver.findElements(By.xpath("//table[@class='table']/tbody/tr")).size(); System.out.println("Row count after filter is: " + rowCount); //Close the browser driver.quit(); }
From source file:com.nexenta.qa.bs.wz.Test1Reg.java
@Test public void registerMe() { WebElement msig = driver.findElement(By.id(reg.MachineSigById)); String machinesig = msig.getAttribute("value"); //String machinesig = driver.findElement(By.id(reg.MachineSigById)).get); logger.info("MSIG: " + machinesig); try {//w w w . ja v a 2 s.c om Process p = Runtime.getRuntime().exec( "/usr/bin/perl /home/user/selenium/utils/nxt-key/gen-com-key.pl " + machinesig + " TRIA 99"); String line; BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); line = in.readLine(); logger.info("LICENCE: " + line); WebElement lic = driver.findElement(By.id(reg.LicenseFieldByID)); lic.clear(); lic.sendKeys(line); in.close(); } catch (IOException e) { e.printStackTrace(); } driver.findElement(By.id(reg.RegisterOK)).click(); driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS); assertEquals(driver.getTitle(), "Nexenta Management View: Appliance and Group Status"); }
From source file:com.nexenta.qa.bs.wz.Test3Registration.java
@Test public void registerMe() { WebElement msig = driver.findElement(By.id(reg.MachineSigById)); String machinesig = msig.getAttribute("value"); //String machinesig = driver.findElement(By.id(reg.MachineSigById)).get); logger.info("MSIG: " + machinesig); try {/*from w w w. j a v a 2s. c o m*/ Process p = Runtime.getRuntime().exec( "perl C:\\Users\\user\\Documents\\perl\\nxt-key\\gen-com-key.pl " + machinesig + " TRIA 99"); String line; BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); line = in.readLine(); logger.info("LICENCE: " + line); WebElement lic = driver.findElement(By.id(reg.LicenseFieldByID)); lic.clear(); lic.sendKeys(line); in.close(); } catch (IOException e) { e.printStackTrace(); } driver.findElement(By.id(reg.RegisterOK)).click(); driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS); assertEquals(driver.getTitle(), "Nexenta Management View: Appliance and Group Status"); }
From source file:com.novartis.opensource.yada.test.YADAAdminTest.java
License:Apache License
/** * Test App Manager new app creation/*from www . j a v a 2 s .co m*/ * @throws InterruptedException if any thread has interrupted the current thread */ @Test(dependsOnMethods = { "testLoginSuccess" }) public void testAppCreation() throws InterruptedException { String t = new String(Long.valueOf(new Date().getTime()).toString()); this.app = "FOO" + t.substring(t.length() < 17 ? 0 : t.length() - 17); WebDriver d = getDriver(); d.findElement(By.id("app-hdr-new")).click(); Thread.sleep(100); Assert.assertTrue(d.findElement(By.id("app-new")).isDisplayed()); d.findElement(By.id("app-code-new")).sendKeys(this.app); d.findElement(By.id("app-active-new")).click(); d.findElement(By.id("app-name-new")).sendKeys(this.app); d.findElement(By.id("app-desc-new")).sendKeys("This is a test of new app functions using app " + this.app); StringBuilder conf = new StringBuilder(); conf.append("jdbcUrl="); conf.append(this.dbUrl); conf.append("\nusername="); conf.append(this.dbUser); conf.append("\npassword="); conf.append(this.dbPw); conf.append("\ndriverClassName="); conf.append(this.dbDriver); conf.append("\nautoCommit=false"); conf.append("\nconnectionTimeout=300000"); conf.append("\nidleTimeout=600000"); conf.append("\nmaxLifetime=1800000"); conf.append("\nminimumIdle=5"); conf.append("\nmaximumPoolSize=100"); WebElement e = d.findElement(By.id("app-conf-new")); e.clear(); e.sendKeys(conf.toString()); d.findElement(By.id("app-submit-new")).click(); e = new WebDriverWait(d, 20) .until(ExpectedConditions.presenceOfElementLocated(By.id("app-hdr-" + this.app))); Assert.assertTrue(e.isDisplayed()); }
From source file:com.novartis.opensource.yada.test.YADAAdminTest.java
License:Apache License
/** * <ol>/* w w w .java2 s. c o m*/ * <li>Opens the query editor</li> * <li>Validates all the buttons are present</li> * <li>Opens the security panel</li> * <li>Sets URL validation policy</li> * <li>Sets TokenValidation policy</li> * <li>Sets ExecutionPolicy</li> * <li>Sets ContentPolicy</li> * </ol> * @throws InterruptedException if any thread has interrupted the current thread * @throws IOException when the test URL can't be accessed */ @Test(dependsOnMethods = { "testNewQueryForNewAppSave" }) public void testSecurityConfigForQuery() throws InterruptedException, IOException { WebDriver d = getDriver(); String protector = this.app + " Test Protector"; this.createQueryForNewApp(" Test Protector", "SELECT 1 AS COL1", "save"); WebElement save = d.findElement(By.id("button-save")); // validate ui WebElement e = new WebDriverWait(d, 20) .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".alert-success"))); String expected = "Hooray! Query " + protector + " was saved successfully."; Assert.assertEquals(e.getText(), expected); Assert.assertFalse(save.isDisplayed()); // close dialog d.findElement(By.id("button-cancel")).click(); Thread.sleep(3000); // restore app-mgr d.findElement(By.id("app")).click(); new WebDriverWait(d, 20).until(ExpectedConditions.presenceOfElementLocated(By.id("app-mgr"))); Thread.sleep(3000); // nav to queries d.findElement(By.id("app-qname-" + this.app)).click(); Thread.sleep(3000); // open query for edit String qname = this.app + " Test Save"; d.findElement(By.xpath("//*[text()[contains(.,\"" + qname + "\")]]")).click(); this.switchToActiveElement(d, 3000); new WebDriverWait(d, 20) .until(ExpectedConditions.presenceOfElementLocated(By.id("query-editor-container"))); // validate buttons List<WebElement> list = d.findElements(By.cssSelector("#query-editor-container .modal-footer button")); Assert.assertEquals(list.size(), 5); for (WebElement b : list) { Assert.assertTrue(b.isDisplayed() && b.isEnabled()); } // open security panel d.findElement(By.id("headingTwo")).click(); Thread.sleep(3000); // Confirm query result String result = getUrl(qname); l.debug("EXPECT NORMAL RESULT:\n" + result); Assert.assertTrue(result.contains(qname) && result.toUpperCase().contains("\"ROWS\":[{\"COL1\":\"1\"}]")); // "Mark this query as secure" and confirm "unauth" d.findElement(By.id("secure-query-ckbx")).click(); d.findElement(By.id("button-save")).click(); Thread.sleep(3000); result = getUrl(qname); l.debug("EXPECT UNAUTHORIZED RESULT:\n" + result); // should be rejected at this point due to checkbox + lack of plugin Assert.assertFalse(result.contains(qname) && result.toUpperCase().contains("\"ROWS\":[{\"COL1\":\"1\"}]")); Assert.assertTrue(result.contains("Server returned HTTP response code: 403")); d.findElement(By.id("button-cancel")).click(); // back to app-mgr Thread.sleep(3000); // open query for edit e = new WebDriverWait(d, 20).until(ExpectedConditions .presenceOfElementLocated(By.xpath("//*[text()[contains(.,\"" + qname + "\")]]"))); e.click(); this.switchToActiveElement(d, 3000); new WebDriverWait(d, 20) .until(ExpectedConditions.presenceOfElementLocated(By.id("query-editor-container"))); if (!d.findElement(By.id("secure-query-ckbx")).isDisplayed()) { d.findElement(By.id("headingTwo")).click(); Thread.sleep(3000); } // confirm "Mark this query as not secure" d.findElement(By.id("secure-query-ckbx")).click(); d.findElement(By.id("button-save")).click(); Thread.sleep(3000); result = getUrl(qname); l.debug("EXPECT NORMAL RESULT:\n" + result); // should be accepted, as box is unchecked Assert.assertTrue(result.contains(qname) && result.toUpperCase().contains("\"ROWS\":[{\"COL1\":\"1\"}]")); d.findElement(By.id("button-cancel")).click(); Thread.sleep(3000); // open query for edit e = new WebDriverWait(d, 20).until(ExpectedConditions .presenceOfElementLocated(By.xpath("//*[text()[contains(.,\"" + qname + "\")]]"))); e.click(); this.switchToActiveElement(d, 3000); new WebDriverWait(d, 20) .until(ExpectedConditions.presenceOfElementLocated(By.id("query-editor-container"))); if (!d.findElement(By.id("secure-query-ckbx")).isDisplayed()) { d.findElement(By.id("headingTwo")).click(); } // l.debug("Sleeping for 2 minutes to enable manual investigation"); Thread.sleep(3000); // validate all components // what is there before any data entry? WebElement plugin = d.findElement(By.className("policy-plugin")); WebElement policyArg = d.findElement(By.className("policy-arg")); WebElement argString = d.findElement(By.className("arg-string")); Assert.assertTrue(d.findElement(By.className("policy-group")).isDisplayed()); Assert.assertTrue(plugin.isDisplayed()); Assert.assertTrue(d.findElement(By.className("policy-action")).isDisplayed()); Assert.assertTrue(argString.isDisplayed()); Assert.assertTrue(d.findElement(By.className("policy-type")).isDisplayed()); Assert.assertTrue(policyArg.isDisplayed()); Assert.assertTrue(d.findElement(By.className("remove-policy")).isDisplayed()); // enter policies // what is there after each policy entry plugin.sendKeys("Gatekeeper"); Select policyType = new Select(d.findElement(By.className("policy-type"))); policyType.selectByVisibleText("URL Pattern Matching"); policyArg.clear(); policyArg.sendKeys("auth.path.rx=^(https?://)?localhost:8080/.+$"); Assert.assertEquals(argString.getText(), "auth.path.rx=^(https?://)?localhost:8080/.+$"); Select policyAction = new Select(d.findElement(By.className("policy-action"))); policyAction.selectByValue("save"); Thread.sleep(2000); policyAction.selectByValue("add-same"); //Thread.sleep(3000); String xpath = "//div[contains(@class,\"security-options\")][2]"; e = new WebDriverWait(d, 20).until(ExpectedConditions.presenceOfElementLocated(By.xpath(xpath))); List<WebElement> policies = d.findElements(By.className("security-options")); List<WebElement> policyTypes = d.findElements(By.className("policy-type")); List<WebElement> policyArgs = d.findElements(By.className("policy-arg")); policyType = new Select(policyTypes.get(1)); policyType.selectByVisibleText("Execution Policy (Indices)"); policyArgs.get(1).clear(); policyArgs.get(1).sendKeys("execution.policy.indices=0:getToken()"); Assert.assertTrue(d.findElement(By.className("policy-protector")).isDisplayed()); d.findElement(By.className("policy-protector")).sendKeys(protector); policyAction.selectByValue("save"); Thread.sleep(3000); policyAction.selectByValue("add-same"); //Thread.sleep(3000); xpath = "//div[contains(@class,\"security-options\")][3]"; e = new WebDriverWait(d, 20).until(ExpectedConditions.presenceOfElementLocated(By.xpath(xpath))); policies = d.findElements(By.className("security-options")); policyTypes = d.findElements(By.className("policy-type")); policyArgs = d.findElements(By.className("policy-arg")); List<WebElement> policyProtectors = d.findElements(By.className("policy-protector")); policyType = new Select(policyTypes.get(2)); policyType.selectByVisibleText("Execution Policy (Columns)"); policyArgs.get(2).clear(); policyArgs.get(2).sendKeys("execution.policy.columns=0:getToken()"); Assert.assertEquals(policyProtectors.size(), 2); policyProtectors.get(1).sendKeys(protector); policyAction.selectByValue("save"); Thread.sleep(2000); policyAction.selectByValue("add-same"); xpath = "(//input[contains(@class,\"security-options\")])[3]"; e = new WebDriverWait(d, 20).until(ExpectedConditions.presenceOfElementLocated(By.xpath(xpath))); policies = d.findElements(By.className("security-options")); policyTypes = d.findElements(By.className("policy-type")); policyArgs = d.findElements(By.className("policy-arg")); policyProtectors = d.findElements(By.className("policy-protector")); policyType = new Select(policyTypes.get(3)); policyType.selectByVisibleText("Content Policy"); policyArgs.get(3).clear(); policyArgs.get(3).sendKeys("content.policy.predicate=x=y"); expected = "auth.path.rx=^(https?://)?localhost:8080.+$,execution.policy.indices=0:getToken(),execution.policy.columns=token:getToken(),content.policy.predicate=x=y"; Assert.assertEquals(argString.getText(), expected); // save // multiple ways to save? (not yet) policyAction.selectByValue("save"); // TODO validate data is in db // TODO validate security works? or is this just for a standard integration test? // TODO alert user when security setting is invalid or unsavable for any reason // TODO alert user to save security settings (this may enable safety net after all) // TODO parse security param into UI when appropriate (it currently doesn't) d.findElement(By.id("button-save")).click(); Thread.sleep(3000); d.findElement(By.id("app")).click(); new WebDriverWait(d, 20).until(ExpectedConditions.presenceOfElementLocated(By.id("app-mgr"))); Thread.sleep(3000); // nav to queries d.findElement(By.id("app-qname-" + this.app)).click(); Thread.sleep(3000); // open query for edit d.findElement(By.xpath("//*[text()[contains(.,\"" + qname + "\")]]")).click(); this.switchToActiveElement(d, 3000); new WebDriverWait(d, 20) .until(ExpectedConditions.presenceOfElementLocated(By.id("query-editor-container"))); d.findElement(By.id("headingThree")).click(); Thread.sleep(3000); String actual = d.findElement(By.cssSelector("$('#default-params tbody tr:eq(0) td input:eq(1)')")) .getAttribute("value"); Assert.assertEquals(actual, expected); }