List of usage examples for org.openqa.selenium WebElement submit
void submit();
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(); }// w w w . j a va2s. 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:scormADL2004.java
License:Open Source License
public void launchTestPackage(String testPackageName) { // Check to see which user should launch the package. checkLoginSession();/*from www. j av a2 s .c o m*/ 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:AndroidRemoteDriverTest.java
/** * @param args the command line arguments *//*w w w . ja va 2 s. co m*/ public static void main(String[] args) { AndroidRemoteWebDriver driver = new AndroidRemoteWebDriver("ws://localhost:9222/devtools/page/4"); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.get("http://www.google.com"); Utils.sleep(2000); WebElement elm = driver.findElement(By.name("q")); Utils.sleep(2000); elm.sendKeys(" // \\ ' * [@id=\"rg_s\"]/div[1]/a "); elm.submit(); //Utils.sleep(2000); elm = driver.findElement(By.partialLinkText("Images")); elm.click(); Utils.sleep(2000); elm = driver.findElement(By.xpath("//*[@id=\"rg_s\"]/div[1]/a")); elm.click(); Utils.sleep(2000); System.out.println("Page source :/n" + driver.getPageSource()); }
From source file:SmokeTester_UnitTest.java
public void executeSmokeTest() throws Exception { // 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", "C:\\Nino\\ChromeWebDriver\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); TestCaseReader tcreader = new TestCaseReader(); List<TestScriptTemplate> tcl = tcreader.readExcel(); List<TestScriptTemplate> validatedTestScript = new ArrayList(); String log_execution = ""; Iterator<TestScriptTemplate> i = tcl.iterator(); while (i.hasNext()) { TestScriptTemplate testscript = i.next(); //collect the results TestScriptTemplate testexecution = new TestScriptTemplate(); testexecution.setAppCode(testscript.getAppCode()); log_execution = log_execution + "\nStart smoke testing for application code: " + testexecution.getAppCode(); //access the URL driver.get(testscript.getAppURL()); //login if not yet if (driver.getCurrentUrl().contains("identity.safeway.com")) { //key in userid and password WebElement weusername = driver.findElement(By.id("username")); //System.out.println("tag:" + weusername.getTagName()); weusername.sendKeys(testscript.getAppUserID()); WebElement wepassword = driver.findElement(By.id("password")); //System.out.println("tag:" + wepassword.getTagName()); wepassword.sendKeys(testscript.getAppPassword()); WebElement weloginform = driver.findElement(By.name("loginData")); //System.out.println("tag:" + weloginform.getTagName()); weloginform.submit(); log_execution = log_execution + " Login Successful"; }//from w w w . j a v a 2 s. co m //recoding URL; required so no need to check for nullity testexecution.setAppURL(driver.getCurrentUrl()); log_execution = log_execution + " Current URL: " + driver.getCurrentUrl(); //recoding title; required so no need to check for nullity testexecution.setHomePageTitle(driver.getTitle()); log_execution = log_execution + " Page Title: " + driver.getTitle(); if (isElementExist(testscript.getHomePageElementType(), testscript.getHomePageElement(), driver)) { System.out.println("Element match!" + testscript.getHomePageElement()); log_execution = log_execution + " Home Page Element validation..."; testexecution.setHomePageElement(testscript.getHomePageElement()); } else { testexecution.setHomePageElement("not found"); } //next page validation if (!testscript.getLevel1URL().isEmpty() || !testscript.getLevel1URL().equals("")) { //go to next level page driver.get(testscript.getLevel1URL()); log_execution = log_execution + " Next Page validation URL: " + testscript.getLevel1URL(); testexecution.setLevel1URL(driver.getCurrentUrl()); System.out.println("execution log: current level 1 URL on set" + testexecution.getLevel1URL()); if (!testscript.getLevel1PageTitle().isEmpty() || !testscript.getLevel1PageTitle().equals("")) { testexecution.setLevel1PageTitle(driver.getTitle()); log_execution = log_execution + " Next Page title validation: " + driver.getTitle(); } if (isElementExist(testscript.getLevel1ElementType(), testscript.getLevel1Element(), driver)) { testexecution.setLevel1Element(testscript.getLevel1Element()); log_execution = log_execution + " Next Page element validation: " + testscript.getLevel1Element(); } else { testexecution.setLevel1Element("not found"); } } testexecution.setLogs(log_execution); SmokeTestValidator_UnitTest testvalidator = new SmokeTestValidator_UnitTest(testscript); TestScriptTemplate testingresult = testvalidator.getTestResult(testexecution); validatedTestScript.add(testingresult); } tcreader.writetoExcel(validatedTestScript); //Close the browser driver.quit(); //return log_execution; }
From source file:CarStoreWebSiteTest.java
@Test public void testInsertNewCar() { String username = "manager"; String password = "7777777"; driver.findElement(By.linkText("Login")).click(); driver.findElement(By.name("user_name")).sendKeys(username); driver.findElement(By.name("user_password")).sendKeys(password); // Look for the submit button (in the login div) and click // to attempt to login WebElement loginButton = driver.findElement(By.name("login")); loginButton.submit(); driver.findElement(By.linkText("Insert")).click(); String license_plate = "ABC0000"; String manufacturer = "Toyota"; String model = "Camry"; String year = "2012"; String color = "red"; String price = "19000.00"; driver.findElement(By.name("license_plate")).sendKeys(license_plate); driver.findElement(By.name("manufacturer")).sendKeys(manufacturer); driver.findElement(By.name("model")).sendKeys(model); driver.findElement(By.name("year")).sendKeys(year); driver.findElement(By.name("color")).sendKeys(color); driver.findElement(By.name("price")).sendKeys(price); driver.findElement(By.name("insert_button")).click(); String correct_value = "Inserted"; String newPage = driver.getPageSource(); assertTrue(newPage.contains(correct_value)); driver.findElement(By.linkText("Delete")).click(); driver.findElement(By.name("license_plate")).sendKeys(license_plate); driver.findElement(By.name("delete_button")).click(); driver.findElement(By.linkText("Logout")).click(); }
From source file:CarStoreWebSiteTest.java
@Test public void testInsertCarThatExists() { String username = "manager"; String password = "7777777"; driver.findElement(By.linkText("Login")).click(); driver.findElement(By.name("user_name")).sendKeys(username); driver.findElement(By.name("user_password")).sendKeys(password); // Look for the submit button (in the login div) and click // to attempt to login WebElement loginButton = driver.findElement(By.name("login")); loginButton.submit(); driver.findElement(By.linkText("Insert")).click(); String license_plate = "ABC0001"; String manufacturer = "Toyota"; String model = "Camry"; String year = "2012"; String color = "red"; String price = "19000.00"; driver.findElement(By.name("license_plate")).sendKeys(license_plate); driver.findElement(By.name("manufacturer")).sendKeys(manufacturer); driver.findElement(By.name("model")).sendKeys(model); driver.findElement(By.name("year")).sendKeys(year); driver.findElement(By.name("color")).sendKeys(color); driver.findElement(By.name("price")).sendKeys(price); driver.findElement(By.name("insert_button")).click(); String correct_value = "There is already a car with this license plate"; String newPage = driver.getPageSource(); assertTrue(newPage.contains(correct_value)); driver.findElement(By.linkText("Logout")).click(); }
From source file:CarStoreWebSiteTest.java
@Test public void testDeleteCarThatExists() { String username = "manager"; String password = "7777777"; driver.findElement(By.linkText("Login")).click(); driver.findElement(By.name("user_name")).sendKeys(username); driver.findElement(By.name("user_password")).sendKeys(password); // Look for the submit button (in the login div) and click // to attempt to login WebElement loginButton = driver.findElement(By.name("login")); loginButton.submit(); driver.findElement(By.linkText("Delete")).click(); String license_plate = "ABC9999"; driver.findElement(By.name("license_plate")).sendKeys(license_plate); driver.findElement(By.name("delete_button")).click(); String correct_value = "There isn't a car with this license plate"; String newPage = driver.getPageSource(); assertTrue(newPage.contains(correct_value)); driver.findElement(By.linkText("Logout")).click(); }
From source file:CarStoreWebSiteTest.java
@Test public void testDeleteCarThatDontExists() { String username = "manager"; String password = "7777777"; driver.findElement(By.linkText("Login")).click(); driver.findElement(By.name("user_name")).sendKeys(username); driver.findElement(By.name("user_password")).sendKeys(password); // Look for the submit button (in the login div) and click // to attempt to login WebElement loginButton = driver.findElement(By.name("login")); loginButton.submit(); String license_plate = "ABC9999"; driver.findElement(By.linkText("Insert")).click(); driver.findElement(By.name("license_plate")).sendKeys(license_plate); driver.findElement(By.name("insert_button")).click(); driver.findElement(By.linkText("Delete")).click(); driver.findElement(By.name("license_plate")).sendKeys(license_plate); driver.findElement(By.name("delete_button")).click(); String correct_value = "Deleted"; String newPage = driver.getPageSource(); assertTrue(newPage.contains(correct_value)); driver.findElement(By.linkText("Logout")).click(); }
From source file:botski.example.AddMeFastExample.java
License:Apache License
public void facebookLogin() throws Exception { driver.get("http://www.facebook.com/"); WebElement formEmail = driver.findElement(By.name("email")); formEmail.sendKeys(facebookEmail);/* w w w . j ava 2 s. c o m*/ WebElement formPassword = driver.findElement(By.name("pass")); formPassword.sendKeys(facebookPassword); WebElement formRemember = driver.findElement(By.name("persistent")); formRemember.sendKeys(" "); formPassword.submit(); if (driver.getCurrentUrl().contains("login.php")) { throw new Exception("Failed to login Facebook as '" + facebookEmail + "' using password '" + facebookPassword + "', I ended up here '" + driver.getCurrentUrl() + "'"); } }
From source file:botski.selenium.SocialBot.java
License:Apache License
/** * @throws Exception //from w w w . j a v a 2 s .com */ public void twitterLogin(String email, String password) throws Exception { browser.get("https://twitter.com/"); WebElement formEmail = browser.findElement(By.id("signin-email")); formEmail.sendKeys(email); WebElement formPassword = browser.findElement(By.id("signin-password")); formPassword.sendKeys(password); formPassword.submit(); String url = browser.getCurrentUrl(); if (url.contains("/login/error")) { throw new Exception("Failed to login Twitter as '" + email + "' using password '" + password + "', I ended up here '" + url + "'"); } }