List of usage examples for org.openqa.selenium By name
public static By name(String name)
From source file:com.mycompany.newseleniumtest.coba.java
public void latihan(String browser) throws InterruptedException { //Instantiate the webdriver object: WebDriver driver = new FirefoxDriver(); JavascriptExecutor jse = (JavascriptExecutor) driver; //Open the web driver.get("http://dev.uangteman.com/admin/"); driver.manage().window().maximize(); Thread.sleep(1500);// w w w .j a v a 2 s . c o m driver.findElement(By.name("bu_name")).sendKeys("rahmat_cs"); driver.findElement(By.name("bu_passwd")).sendKeys("testing"); driver.findElement(By.cssSelector("button[class='btn btn-orange btn-squared pull-right ladda-button']")) .click(); Thread.sleep(2500); jse.executeScript("window.scrollBy(0,1500)", ""); jse.executeScript("window.scroll(0,1500)", ""); WebElement scroll = driver.findElement(By.xpath( "/html/body/div[2]/div[2]/div/div[2]/div/div/div[3]/div/div[2]/div/form/table/tbody/tr[1]/td[12]/span")); JavascriptExecutor js = (JavascriptExecutor) driver; jse.executeScript( "document.getElementByxpath('/html/body/div[2]/div[2]/div/div[2]/div/div/div[3]/div/div[2]/div/form/table/tbody/tr[1]/td[12]/span').scrollLeft += 250", ""); //Get page title in selenium webdriver String actual = driver.getTitle(); }
From source file:com.mycompany.newseleniumtest.TestScript.java
public boolean workbenchLogin(String user) { boolean output = true; try {/*from w w w . j a v a 2 s .co m*/ this.startDriver("firefox"); this.driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); WebDriverWait wait = new WebDriverWait(driver, 10); //Open the page this.driver.get("http://" + this.testLocation + ".uangteman.com/admin"); // this.driver.get("localhost:80/uang-teman/admin"); WebElement main; switch (user) { case ("finance"): this.driver.findElement(By.name("bu_name")).sendKeys("ddebora_fi"); break; case ("admin"): this.driver.findElement(By.name("bu_name")).sendKeys("pras_admin"); break; case ("staff"): this.driver.findElement(By.name("bu_name")).sendKeys("rahmat_staff"); break; case ("fraudcheck"): this.driver.findElement(By.name("bu_name")).sendKeys("pras_fc"); break; case ("customerservice"): this.driver.findElement(By.name("bu_name")).sendKeys("rahmat_cs"); break; case ("pras_supermanager"): this.driver.findElement(By.name("bu_name")).sendKeys("pras_supermanager"); break; case ("supermanager_redho"): this.driver.findElement(By.name("bu_name")).sendKeys("redho"); break; case ("fauzan"): this.driver.findElement(By.name("bu_name")).sendKeys("fauzan"); break; case ("pras_manager"): this.driver.findElement(By.name("bu_name")).sendKeys("pras_manager"); break; case ("ddebora_mgr"): this.driver.findElement(By.name("bu_name")).sendKeys("ddebora_mgr"); break; case ("fahmy_manager"): this.driver.findElement(By.name("bu_name")).sendKeys("fahmy_manager"); break; case ("eka"): this.driver.findElement(By.name("bu_name")).sendKeys("eka"); break; case ("collection"): this.driver.findElement(By.name("bu_name")).sendKeys("kevincol"); break; default: throw new Exception("No user"); } this.driver.findElement(By.name("bu_passwd")).sendKeys("testing"); main = this.driver.findElement( By.cssSelector("button[class='btn btn-orange btn-squared pull-right ladda-button']")); main.submit(); //SMS verifications if (!this.testLocation.equals("dev")) { Thread.sleep(5000); String sms_code = (String) SupportController.getfromDatabase( "SELECT bua_auth_code FROM bo_auth_log ORDER BY bua_id DESC LIMIT 1;", this.testLocation); this.driver.findElement(By.name("authcode")).sendKeys(sms_code); this.driver .findElement(By .cssSelector("button[class='btn btn-bricky btn-squared pull-right ladda-button']")) .click(); } } catch (Exception e) { System.out.println("TestScript Login-Error: " + e.getMessage()); output = false; } finally { return output; } }
From source file:com.mycompany.newseleniumtest.TestScript2.java
public boolean workbenchLogin(String user) { boolean output = true; try {//w w w . j a va 2s . c om this.startDriver("firefox"); this.driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); WebDriverWait wait = new WebDriverWait(driver, 10); //Open the page this.driver.get("http://" + this.testLocation + ".uangteman.com/admin"); // this.driver.get("localhost:80/uang-teman/admin"); WebElement main; switch (user) { case ("finance"): this.driver.findElement(By.name("bu_name")).sendKeys("ddebora_fi"); break; case ("admin"): this.driver.findElement(By.name("bu_name")).sendKeys("pras_admin"); break; case ("staff"): this.driver.findElement(By.name("bu_name")).sendKeys("pras_staff"); break; case ("fraudcheck"): this.driver.findElement(By.name("bu_name")).sendKeys("pras_fc"); break; case ("customerservice"): this.driver.findElement(By.name("bu_name")).sendKeys("pras_supercs"); break; case ("pras_supermanager"): this.driver.findElement(By.name("bu_name")).sendKeys("pras_supermanager"); break; case ("supermanager_redho"): this.driver.findElement(By.name("bu_name")).sendKeys("redho"); break; case ("fauzan"): this.driver.findElement(By.name("bu_name")).sendKeys("fauzan"); break; case ("pras_manager"): this.driver.findElement(By.name("bu_name")).sendKeys("pras_manager"); break; case ("ddebora_mgr"): this.driver.findElement(By.name("bu_name")).sendKeys("ddebora_mgr"); break; case ("fahmy_manager"): this.driver.findElement(By.name("bu_name")).sendKeys("fahmy_manager"); break; case ("eka"): this.driver.findElement(By.name("bu_name")).sendKeys("eka"); break; case ("collection"): this.driver.findElement(By.name("bu_name")).sendKeys("kevincol"); break; default: throw new Exception("No user"); } this.driver.findElement(By.name("bu_passwd")).sendKeys("testing"); main = this.driver.findElement( By.cssSelector("button[class='btn btn-orange btn-squared pull-right ladda-button']")); main.submit(); //SMS verifications if (!this.testLocation.equals("dev")) { Thread.sleep(5000); String sms_code = (String) SupportController.getfromDatabase( "SELECT bua_auth_code FROM bo_auth_log ORDER BY bua_id DESC LIMIT 1;", this.testLocation); this.driver.findElement(By.name("authcode")).sendKeys(sms_code); this.driver .findElement(By .cssSelector("button[class='btn btn-bricky btn-squared pull-right ladda-button']")) .click(); } } catch (Exception e) { System.out.println("TestScript Login-Error: " + e.getMessage()); output = false; } finally { return output; } }
From source file:com.mycompany.selenium.SeleniumExample.java
public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "/Applications/chromedriver"); // Create a new instance of the Firefox driver // Notice that the remainder of the code relies on the interface, // not the implementation. WebDriver driver = new ChromeDriver(); // System.setProperty("webdriver.chrome.driver", "/Users/CosticaTeodor/Downloads/drivers/chromedriver"); // And now use this to visit Google driver.get("http://www.google.com"); // Alternatively the same thing can be done like this // driver.navigate().to("http://www.google.com"); // Find the text input element by its name WebElement element = driver.findElement(By.name("q")); // Enter something to search for element.sendKeys("Cheese!"); // Now submit the form. WebDriver will find the form for us from the element element.submit();/*from www . ja v a2s . c o m*/ // Check the title of the page System.out.println("Page title is: " + driver.getTitle()); // Google's search is rendered dynamically with JavaScript. // Wait for the page to load, timeout after 10 seconds (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().toLowerCase().startsWith("cheese!"); } }); // Should see: "cheese! - Google Search" System.out.println("Page title is: " + driver.getTitle()); //Close the browser driver.quit(); }
From source file:com.mycompany.seliniumtest.Selenium2Example.java
public static void main(String[] args) { System.setProperty("webdriver.gecko.driver", "/usr/local/Cellar/geckodriver/geckodriver"); // Create a new instance of the Firefox driver // Notice that the remainder of the code relies on the interface, // not the implementation. //WebDriver driver = new FirefoxDriver(); //WebDriver driver = new ChromeDriver(); WebDriver driver = new FirefoxDriver(); //WebDriver driver = new HtmlUnitDriver(); // And now use this to visit Google driver.get("http://www.google.com"); // Alternatively the same thing can be done like this // driver.navigate().to("http://www.google.com"); // Find the text input element by its name WebElement element = driver.findElement(By.name("q")); // Enter something to search for element.sendKeys("Cheese!"); // Now submit the form. WebDriver will find the form for us from the element element.submit();//from w w w . j av a 2 s . com // Check the title of the page System.out.println("Page title is: " + driver.getTitle()); // Google's search is rendered dynamically with JavaScript. // Wait for the page to load, timeout after 10 seconds (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().toLowerCase().startsWith("cheese!"); } }); // Should see: "cheese! - Google Search" System.out.println("Page title is: " + driver.getTitle()); //Close the browser driver.quit(); }
From source file:com.mycompany.webcalculator.OperationsSeleniumTest.java
public void login(WebDriver driver, String siteURL, String username, String password) { driver.get(siteURL);//from w ww .j ava 2 s . c o m System.out.println(siteURL); //wait.until(ExpectedConditions.presenceOfElementLocated(By.id("userid"))); System.out.println("Loading URL.."); //extent.log(LogStatus.INFO, "Images", "Image:", imageMap + imageName); // takeScreenShot(caseName); screenshot.Capture(driver, imageLocation); driver.findElement(By.name("em")).clear(); System.out.println("Waiting for User Id..."); driver.findElement(By.name("em")).sendKeys(username); System.out.println("User Id " + username + " entered."); screenshot.Capture(driver, imageLocation); //takeScreenShot("test 2"); driver.findElement(By.name("pw")).clear(); System.out.println("Waiting for Password..."); driver.findElement(By.name("pw")).sendKeys(password); System.out.println("Password ******* entered."); screenshot.Capture(driver, imageLocation); //driver.findElement(By.xpath("//button[text()='Submit']")).click(); driver.findElement(By.name("Login")).click(); System.out.println("Logging in..."); screenshot.Capture(driver, imageLocation); assertTrue(driver.getPageSource().contains("Invalid login. Please try again")); }
From source file:com.nabla.project.fronter.selenium.tests.GoogleSearchSTest.java
License:Open Source License
@Test public void testGoogleSearch() { // try//from w ww . j a va2s. c o m // { // Find the text input element by its name final WebElement element = this.driver.findElement(By.name("q")); // Enter something to search for element.sendKeys("Selenium testing tools cookbook"); // Now submit the form. WebDriver will find the form for us from the element element.submit(); // Google's search is rendered dynamically with JavaScript. // Wait for the page to load, timeout after 10 seconds (new WebDriverWait(this.driver, 10)).until(new ExpectedCondition<Boolean>() { @Override public Boolean apply(final WebDriver d) { return d.getTitle().toLowerCase().startsWith("selenium testing tools cookbook"); } }); // Should see: selenium testing tools cookbook - Google Search // Assert.assertEquals("Selenium testing tools cookbook - Google Search", this.driver.getTitle()); Assert.assertEquals("Selenium testing tools cookbook - Recherche Google", this.driver.getTitle()); /* * } catch (final Error e) * { * // Capture and append Exceptions/Errors * this.verificationErrors.append(e.toString()); * } */ }
From source file:com.nabla.project.fronter.selenium.tests.pageobjects.RollsPage.java
License:Open Source License
@And("he Submits request for score calculation") public void He_submits_request_for_score() { final WebDriverWait wait = new WebDriverWait(SeleniumHelper.getDriver(), 10); wait.until(ExpectedConditions.elementToBeClickable(By.name("rolls_form:score"))); SeleniumHelper.getDriver().manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); this.calculate.click(); }
From source file:com.nabla.project.fronter.selenium.tests.SimpleWebDriverSTest.java
License:Open Source License
public void testWithWrongInputS() throws Exception { // Get the StopWatch Object and start the StopWatch final StopWatch pageLoad = new StopWatch(); pageLoad.start();/* w w w . j a va2 s . c o m*/ // Create an instance of Loan Page class // and provide the driver final RollsPage loanPage = new RollsPage(/* SeleniumHelper.getDriver() */); // Open the Loan Calculator Page loanPage.get(); loanPage.He_enters_rolls("ABC"); // wait for the application to get fully loaded /* * final WebElement findOwnerLink = (new WebDriverWait(SeleniumHelper.getDriver(), 5)).until(new ExpectedCondition<WebElement>() * { * @Override * public WebElement apply(final WebDriver d) * { * // d.get(baseUrl); * return d.findElement(By.name("loan_form:paybackTime")); * } * }); * findOwnerLink.click(); */ final WebDriverWait wait = new WebDriverWait(SeleniumHelper.getDriver(), 10); wait.until(ExpectedConditions.elementToBeClickable(By.name("rolls_form:score"))); SeleniumHelper.getDriver().manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); SeleniumHelper.getDriver().findElement(By.name("rolls_form:score")).click(); loanPage.Ensure_a_transaction_failure_message(2, "Please enter the amount of your loan. Ex. 200000: Validation Error: Specified attribute is not between the expected values of 1 and 1,000,000,000."); loanPage.Ensure_a_transaction_failure_message(3, "Please enter the number of years you have to pay back your loan. Ex. 30: Validation Error: Specified attribute is not between the expected values of 1 and 120."); SeleniumHelper.testTakesScreenshot("testWithWrongInputS.png", SeleniumHelper.getDriver()); // Thread.sleep(1000); SeleniumHelper.getSelenium().open("/fronter/"); SeleniumHelper.getSelenium().waitForPageToLoad("1500"); }
From source file:com.nabla.project.visma.selenium.tests.pageobjects.LoanPage.java
License:Open Source License
@And("he Submits request for Payment's Schedule") public void He_submits_request_for_fund_transfer() throws InterruptedException { final WebDriverWait wait = new WebDriverWait(SeleniumHelper.getDriver(), 10); wait.until(ExpectedConditions.elementToBeClickable(By.name("loan_form:payment"))); SeleniumHelper.getDriver().manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); this.calculate.click(); SeleniumHelper.getSelenium().waitForPageToLoad(SeleniumHelper.PAGE_TO_LOAD_TIMEOUT); // SeleniumHelper.getDriver().findElement(By.name("loan_form:payment")).click(); // Thread.sleep(10000); // 10 s }