List of usage examples for org.openqa.selenium.support.ui Select Select
public Select(WebElement element)
From source file:scormADL2004.java
License:Open Source License
/** * Select All valid tests to perform in ADL 2004 Test Suite * @param testsToExecute// ww w . j a v a2 s .c o m */ public void initialiseTestSuite(String[] testsToExecute) { driver.switchTo().window(""); driver.switchTo().frame("instructions"); Select multipleTestsSelect = new Select(driver.findElement(By.id("possible"))); multipleTestsSelect.deselectAll(); for (int i = 0; i < testsToExecute.length; i++) { multipleTestsSelect.selectByVisibleText(testsToExecute[i]); } // Workaround for Selenium bug - 1020, to be fixed in 2.5.0 driver.findElement(By.id("add")).sendKeys(Keys.ENTER); driver.switchTo().window(""); driver.switchTo().frame("controls"); driver.findElement(By.id("continue")).click(); try { driver.switchTo().alert().accept(); } catch (NoAlertPresentException ex) { } }
From source file:JUnitTestClass.java
@Test public void Test_Dropdowns() throws Exception { Select dropdown1 = new Select(driver.findElement(By.id("dropdown_1"))); dropdown1.selectByVisibleText("Mercedes"); Select dropdown2 = new Select(driver.findElement(By.id("dropdown_2"))); dropdown2.selectByVisibleText("Saab"); Select dropdown3 = new Select(driver.findElement(By.id("dropdown_3"))); dropdown3.selectByVisibleText("Saab"); Select dropdown4 = new Select(driver.findElement(By.id("dropdown_4"))); dropdown4.selectByVisibleText("Audi"); }
From source file:ExpiredLicenseSelenium.java
@Test public void testAddLicenseWebDriver() throws Exception { Date now = new java.util.Date(); String ts = new Timestamp(now.getTime()).toString(); String validTill = addDays(now, 15); driver.get(baseUrl + "#/"); driver.findElement(By.linkText("Start licensing process")).click(); driver.findElement(By.id("nameOrganization")).clear(); driver.findElement(By.id("nameOrganization")).sendKeys(ts); driver.findElement(By.id("applicationArea")).clear(); driver.findElement(By.id("applicationArea")).sendKeys("ApplicationAreaTest"); driver.findElement(By.id("nameContact")).clear(); driver.findElement(By.id("nameContact")).sendKeys("NameTest"); driver.findElement(By.id("email")).clear(); driver.findElement(By.id("email")).sendKeys("email@test"); driver.findElement(By.id("skype")).clear(); driver.findElement(By.id("skype")).sendKeys("SkypeTest"); driver.findElement(By.id("phone")).clear(); driver.findElement(By.id("phone")).sendKeys("PhoneTest"); driver.findElement(By.cssSelector("div.form-group > button.btn.btn-default")).click(); new Select(driver.findElement(By.id("product"))).selectByVisibleText("i-Voting 11.2"); driver.findElement(/*from w ww .ja v a 2 s . c om*/ By.cssSelector("form[name=\"chooseProductForm\"] > div.form-group > button.btn.btn-default")) .click(); driver.findElement(By.id("validFrom")).clear(); driver.findElement(By.id("validFrom")).sendKeys("1900-01-01"); driver.findElement(By.id("validTill")).clear(); driver.findElement(By.id("validTill")).sendKeys(validTill); driver.findElement(By.id("addLicenseSubmit")).click(); //Check if license is expiring driver.findElement(By.xpath("//div[@id='bs-example-navbar-collapse-1']/ul[2]/li[2]/a/span/i[2]")).click(); //TODO Add a check based on id instead of validFrom/validTill dates List<WebElement> list = driver.findElements(By.xpath("//*[contains(text(),'" + "1900-01-01" + "')]")); Assert.assertTrue("License not found!", list.size() > 0); List<WebElement> list2 = driver.findElements(By.xpath("//*[contains(text(),'" + validTill + "')]")); Assert.assertTrue("License not found!", list2.size() > 0); }
From source file:StateContentTest.java
public void selectState(String state) throws InterruptedException { try {// ww w.j a v a2s .com new Select(driver.findElement(By.id("statesel"))).selectByVisibleText(state); driver.findElement(By.id("stateSelectionContinue")).click(); } catch (WebDriverException w) { driver.findElement(By.cssSelector("div.select-state > a")).click(); Thread.sleep(1000); new Select(driver.findElement(By.id("statesel"))).selectByVisibleText(state); driver.findElement(By.id("stateSelectionContinue")).click(); } }
From source file:StateContentTest.java
public void testSignUpPage(String state) throws InterruptedException { driver.findElement(By.cssSelector("a.btn.btn-primary")).click(); assertEquals(copyMatrix.get(state)[4].trim(), driver.findElement(By.id("courseReasonDesc")).getText().trim()); driver.findElement(By.id("confirmState")).click(); Thread.sleep(300);// w w w . jav a2 s . co m switch (state) { case "Alaska": case "California": case "Delaware": case "District of Columbia": case "Michigan": case "Minnesota": case "Pennsylvania": case "West Virginia": assertEquals(copyMatrix.get(state)[5].trim(), driver.findElement(By.id("id=REFRESHER-Q")).getText().trim()); driver.findElement(By.xpath("(//a[contains(text(),'?')])[3]")).click(); Thread.sleep(300); assertEquals(copyMatrix.get(state)[6].trim(), driver.findElement(By.id("id=REFRESHER-TIP")).getText().trim()); driver.findElement(By.cssSelector( "#refresherpop > div.modal-dialog > div.modal-content > div.modal-header > button.close.btn-close")) .click(); new Select(driver.findElement(By.id("DLTYPE"))).selectByVisibleText("CLASS A"); new Select(driver.findElement(By.id("COURSEREASON"))).selectByVisibleText("Court Referral"); default: driver.findElement(By.id("continueCourseOptions")).click(); break; } Thread.sleep(300); driver.findElement(By.id("CCNAME")).clear(); driver.findElement(By.id("CCNAME")).sendKeys("test test"); driver.findElement(By.id("cc")).clear(); driver.findElement(By.id("cc")).sendKeys("4111111111111111"); new Select(driver.findElement(By.id("CCMONTH"))).selectByVisibleText("04 (Apr)"); new Select(driver.findElement(By.id("CCYEAR"))).selectByVisibleText("2018"); driver.findElement(By.id("CCCVV")).clear(); driver.findElement(By.id("CCCVV")).sendKeys("0000"); driver.findElement(By.id("CCEMAIL")).clear(); driver.findElement(By.id("CCEMAIL")).sendKeys("kyle.erickson@thomasarts.com"); driver.findElement(By.id("CCCEMAIL")).clear(); driver.findElement(By.id("CCCEMAIL")).sendKeys("kyle.erickson@thomasarts.com"); driver.findElement(By.id("PASSWORD")).clear(); driver.findElement(By.id("PASSWORD")).sendKeys("password1"); driver.findElement(By.id("CPASSWORD")).clear(); driver.findElement(By.id("CPASSWORD")).sendKeys("password1"); driver.findElement(By.id("TERMS")).click(); driver.findElement(By.id("coursePurchase")).click(); Thread.sleep(300); //assertEquals("Thank you for your purchase!", driver.findElement(By.cssSelector("h1")).getText()); // driver.findElement(By.id("FIRSTNAME")).clear(); // driver.findElement(By.id("FIRSTNAME")).sendKeys("test"); // driver.findElement(By.id("LASTNAME")).clear(); // driver.findElement(By.id("LASTNAME")).sendKeys("test"); // driver.findElement(By.id("ADDRESS1")).clear(); // driver.findElement(By.id("ADDRESS1")).sendKeys("555 fake st."); // driver.findElement(By.id("CITY")).clear(); // driver.findElement(By.id("CITY")).sendKeys("faketown"); // driver.findElement(By.id("ZIP")).clear(); // driver.findElement(By.id("ZIP")).sendKeys("84015"); // new Select(driver.findElement(By.id("DATEOFBIRTH_MONTH"))).selectByVisibleText("MAY"); // new Select(driver.findElement(By.id("DATEOFBIRTH_DAY"))).selectByVisibleText("4"); // new Select(driver.findElement(By.id("DATEOFBIRTH_YEAR"))).selectByVisibleText("1915"); // driver.findElement(By.id("radio")).click(); // driver.findElement(By.id("PHONE")).clear(); // driver.findElement(By.id("PHONE")).sendKeys("555-555-5555"); // driver.findElement(By.id("DL")).clear(); // driver.findElement(By.id("DL")).sendKeys("555555555"); // driver.findElement(By.name("submit")).click(); }
From source file:StateContentTest.java
public void testGiftPaymentPage(String state) throws InterruptedException { loadPage(false);//from ww w .j ava 2 s.co m driver.findElement(By.xpath("//a[contains(text(),'Purchase the course as a gift')]")).click(); driver.findElement(By.cssSelector("p.sta-link > a > span")).click(); Thread.sleep(300); assertEquals(copyMatrix.get(state)[21].trim(), driver.findElement(By.cssSelector( "#stateInfo-gifter > div.modal-dialog > div.modal-content > div.modal-body > p")).getText() .trim()); driver.findElement(By.cssSelector( "#stateInfo-gifter > div.modal-dialog > div.modal-content > div.modal-header > button.close.btn-close")) .click(); Thread.sleep(300); driver.findElement(By.id("confirmState")).click(); driver.findElement(By.id("RNAME")).clear(); driver.findElement(By.id("RNAME")).sendKeys("Test Test"); driver.findElement(By.id("REMAIL")).clear(); driver.findElement(By.id("REMAIL")).sendKeys("test@test.test"); driver.findElement(By.id("CREMAIL")).clear(); driver.findElement(By.id("CREMAIL")).sendKeys("test@test.test"); driver.findElement(By.id("FROMANME")).clear(); driver.findElement(By.id("FROMANME")).sendKeys("test"); driver.findElement(By.id("continueCourseOptions")).click(); driver.findElement(By.id("CCNAME")).clear(); driver.findElement(By.id("CCNAME")).sendKeys("test"); driver.findElement(By.id("cc")).clear(); driver.findElement(By.id("cc")).sendKeys("4111111111111111"); new Select(driver.findElement(By.id("CCMONTH"))).selectByVisibleText("04 (Apr)"); new Select(driver.findElement(By.id("CCYEAR"))).selectByVisibleText("2018"); driver.findElement(By.id("CCCVV")).clear(); driver.findElement(By.id("CCCVV")).sendKeys("0000"); driver.findElement(By.id("CCEMAIL")).clear(); driver.findElement(By.id("CCEMAIL")).sendKeys("test@test.test"); driver.findElement(By.id("CCCEMAIL")).clear(); driver.findElement(By.id("CCCEMAIL")).sendKeys("test@test.test"); driver.findElement(By.id("TERMS")).click(); driver.findElement(By.id("coursePurchase")).click(); Thread.sleep(3000); assertEquals("Thank you for your gift purchase!", driver.findElement(By.cssSelector("h1")).getText()); }
From source file:CarStoreWebSiteTest.java
@Test public void testSearchWithMultipleFilterAnd() { String model = "Veloster"; String color = "red"; driver.findElement(By.linkText("Search")).click(); driver.findElement(By.name("model")).sendKeys(model); driver.findElement(By.name("color")).sendKeys(color); Select dropdown = new Select(driver.findElement(By.name("color_logical"))); dropdown.selectByValue(" AND "); driver.findElement(By.name("search_button")).click(); String newPage = driver.getPageSource(); String correct_value = "ABC0006"; assertTrue(newPage.contains(correct_value)); }
From source file:CarStoreWebSiteTest.java
@Test public void testSearchWithMultipleFilterOR() { String color = "silver"; String price = "18000.00"; driver.findElement(By.linkText("Search")).click(); driver.findElement(By.name("color")).sendKeys(color); driver.findElement(By.name("price")).sendKeys(price); Select dropdown = new Select(driver.findElement(By.name("price_logical"))); dropdown.selectByValue(" OR "); driver.findElement(By.name("search_button")).click(); String newPage = driver.getPageSource(); System.out.println(newPage);/*from w ww . ja v a 2 s.c o m*/ String correct_value; correct_value = "ABC0006"; assertTrue(newPage.contains(correct_value)); correct_value = "ABC0007"; assertTrue(newPage.contains(correct_value)); }
From source file:UploadTest.java
@Test public void uploadOK() { driver.get(baseUrl + "/samplecenter/faces/index.xhtml"); driver.findElement(By.linkText("Upload")).click(); driver.findElement(By.id("j_idt20:title")).clear(); driver.findElement(By.id("j_idt20:title")).sendKeys(title); driver.findElement(By.id("j_idt20:tag")).clear(); driver.findElement(By.id("j_idt20:tag")).sendKeys(tag); driver.findElement(By.id("j_idt20:file")).clear(); driver.findElement(By.id("j_idt20:file")).sendKeys(file); driver.findElement(By.xpath("//li[@id='j_idt20:j_idt26:0']/span/span")).click(); driver.findElement(By.xpath("//li[@id='j_idt20:j_idt26:0_1']/span/span[3]")).click(); new Select(driver.findElement(By.id("j_idt20:fkAuthor"))).selectByVisibleText(fkAuthor); driver.findElement(By.linkText("Save")).click(); if (outputString.equalsIgnoreCase(driver.findElement(By.cssSelector("td")).getText())) { System.out.println("Test OK"); } else {//from w w w . ja va 2 s . c om System.out.println(driver.findElement(By.cssSelector("td")).getText()); System.out.println("Test KO"); } }
From source file:Practice01.java
public static void main(String[] args) throws InterruptedException { WebDriver driver = new FirefoxDriver(); // Open Website driver.get("https://enterprise-demo.orangehrmlive.com/auth/login"); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // Type Username driver.findElement(By.xpath("//input[@id='txtUsername']")).sendKeys("Admin"); // Type Password driver.findElement(By.cssSelector("#txtPassword")).sendKeys("admin"); // Click on Login driver.findElement(By.id("btnLogin")).click(); // Click on PIM driver.findElement(By.id("menu_pim_viewPimModule")).click(); // Click Add Employee driver.findElement(By.xpath("//a[@id='menu_pim_addEmployee']")).click(); // DateFormat dateFormat = new SimpleDateFormat("ddhhss"); // Date date = new Date(); // String date1 = dateFormat.format(date); // String userName = "John"+date1; // String username1= "Smith"+date1; // Type First name driver.findElement(By.id("firstName")).sendKeys("John"); // Type Last name driver.findElement(By.id("lastName")).sendKeys("Smith"); Random random = new Random(); int eID = random.nextInt(1000); // Click on Location driver.findElement(By.id("employeeId")).clear(); driver.findElement(By.id("employeeId")).sendKeys("" + eID); // Click on//from w w w. j a v a 2 s. c o m WebElement location_dd = driver.findElement(By.xpath("//select[@id='location']")); Select location = new Select(location_dd); location.selectByIndex(9); // Click Save driver.findElement(By.id("btnSave")).click(); // Click on edit driver.findElement(By.xpath("//input[@value='Edit']")).click(); // Click on licences expiry driver.findElement(By.id("personal_txtLicExpDate")).click(); // Select date driver.findElement(By.xpath("html/body/div[4]/table/tbody/tr[5]/td[2]/a")).click(); // Click on marital box driver.findElement(By.id("personal_cmbMarital")).click(); // Click on married driver.findElement(By.xpath("//select[@name='personal[cmbMarital]']/option[3]")).click(); // Click on Dob box driver.findElement(By.id("personal_DOB")).click(); //click month box Select month_dd = new Select(driver.findElement(By.xpath("//div[@class='ui-datepicker-title']/select[1]"))); month_dd.selectByVisibleText("Jul"); // Select Year Select year_dd = new Select(driver.findElement(By.xpath("//div/select[2]"))); year_dd.selectByIndex(35); // Click on Date driver.findElement(By.xpath("//table/tbody/tr[4]/td[4]/a")).click(); // Click Save driver.findElement(By.id("btnSave")).click(); // Verify Successfully Saved Message //Assert Assert.assertTrue("Successfully Saved", driver.findElement(By.xpath("html/body/div[1]/div[3]/div/div[2]/div[2]/div")).isEnabled()); System.out.println("Successfully Saved"); //assert1 // String expectedText = "Successfully Saved"; // String actualText = driver.findElement(By.xpath("html/body/div[1]/div[3]/div/div[2]/div[2]/div")).getText(); // Assert.assertEquals(expectedText,actualText); // Click Employee List driver.findElement(By.id("menu_pim_viewEmployeeList")).click(); // Thread.sleep(3000); // //click on emp name // driver.findElement(By.xpath("//input[@id='empsearch_employee_name_empName']")).sendKeys(userName + username1); // // Type Employee ID // driver.findElement(By.id("empsearch_id")).sendKeys(" "+eID); // // Clear Employee ID // driver.findElement(By.id("empsearch_id")).clear(); Thread.sleep(2000); // Search Emp by ID driver.findElement(By.id("empsearch_id")).sendKeys("" + eID); // Search Employee By ID // driver.findElement(By.id("searchBtn")).click(); Thread.sleep(2000); driver.findElement(By.id("searchBtn")).click(); //Assert Assert.assertTrue("John", driver.findElement(By.xpath("//tbody/tr/td[3]/a")).isEnabled()); System.out.println("John"); // }