List of usage examples for org.openqa.selenium.support.ui Select selectByVisibleText
@Override public void selectByVisibleText(String text)
From source file:scormADL2004.java
License:Open Source License
/** * Select All valid tests to perform in ADL 2004 Test Suite * @param testsToExecute/*from w w w .j a v a 2 s . co 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: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 ww. java2s. c om*/ 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"); // }
From source file:administrationedit.setSeasonTemplate.java
public static void main(String[] args) throws InterruptedException { for (int y = 0; y < 2; y++) { System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe"); driver = new ChromeDriver(); WebDriverWait wait = new WebDriverWait(driver, 3); driver.manage().window().maximize(); Random r = new Random(); Faker faker = new Faker(); driver.get("https://goldfish.dev.hexis.hr/demo/en/administration/accommodation/seasonTemplateAdd"); adminLogin login = new adminLogin(driver); login.loginToAdmin("demo", "demo"); int currentYear = Calendar.getInstance().get(Calendar.YEAR) + y; String curYear = String.valueOf(currentYear); // Input name of template driver.findElement(By.id("name")).sendKeys("Season-" + curYear); // Choose year Select year = new Select(driver.findElement(By.id("year"))); year.selectByVisibleText(curYear); // Now select seasons WebElement tableId = driver.findElement(By.xpath("//*[@class='ui-calendar hasDatepicker']")); if (year.getFirstSelectedOption().getText().equals(curYear)) { String id = tableId.getAttribute("id"); for (int i = 1; i <= 12; i++) { Thread.sleep(1000); for (int j = 1; j <= 7; j++) { if (!driver.findElements(By.xpath( "//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[1]/td[" + j + "]/a")) .isEmpty()) { driver.findElement(By.xpath( "//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[1]/td[" + j + "]/a")) .click(); break; }//from ww w. j a v a2 s. co m } i++; int weeks = driver .findElements(By.xpath("//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr")) .size(); int test = 0; for (int j = 7; j >= 1; j--) { if (!driver.findElements(By.xpath("//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[" + weeks + "]/td[" + j + "]/a")).isEmpty()) { test = 1; break; } else test = 2; } switch (test) { case 1: for (int j = 7; j >= 1; j--) { if (!driver.findElements(By.xpath("//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[" + weeks + "]/td[" + j + "]/a")).isEmpty()) { driver.findElement(By.xpath("//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[" + weeks + "]/td[" + j + "]/a")).click(); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath( "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[3]/div/select"))); Select season1 = new Select(driver.findElement(By.xpath( "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[3]/div/select"))); int season1int = r.nextInt(season1.getOptions().size() - 1) + 1; season1.selectByIndex(season1int); driver.findElement(By.xpath( "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[4]/div/a[2]")) .click(); break; } } break; case 2: for (int j = 7; j >= 1; j--) { if (!driver.findElements(By.xpath("//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[" + (weeks - 1) + "]/td[" + j + "]/a")).isEmpty()) { driver.findElement(By.xpath("//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[" + (weeks - 1) + "]/td[" + j + "]/a")).click(); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath( "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[3]/div/select"))); Select season2 = new Select(driver.findElement(By.xpath( "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[3]/div/select"))); int season2int = r.nextInt(season2.getOptions().size() - 1) + 1; season2.selectByIndex(season2int); driver.findElement(By.xpath( "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[4]/div/a[2]")) .click(); break; } } } } } // SAVE wait.until(ExpectedConditions.visibilityOfElementLocated( By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[3]/div/input"))); driver.findElement(By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[3]/div/input")) .click(); if (driver.getTitle().equals("Accommodation season templates administration")) { driver.close(); } } }
From source file:ca.pe.cjsigouin.testinator.selenium.WebDriverMain.java
public static void main(String[] args) { System.setProperty("webdriver.gecko.driver", "/home/krystofurr/Programs/selenium/geckodriver"); System.setProperty("webdriver.chrome.driver", "/home/krystofurr/Programs/selenium/chromedriver"); // WebDriver driver = new FirefoxDriver(); WebDriver driver = new ChromeDriver(); // WebDriver driver = new InternetExplorerDriver(); //Puts an Implicit wait, Will wait for 10 seconds before throwing exception driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); //Launch website driver.navigate().to(CommonConstants.HOST + CommonConstants.URL_LOGIN); driver.findElement(By.id("emailAddress")).sendKeys("cjsigouin@gov.pe.ca"); driver.findElement(By.id("password")).sendKeys("Test12345!"); driver.findElement(By.id("loginButton")).click(); WebDriverWait wait = new WebDriverWait(driver, 5); wait.until(/*from w w w .j a v a 2 s . c om*/ ExpectedConditions.elementToBeClickable(By.xpath(".//*[@id='serviceWellSection']/div[2]/div/a/b"))); driver.get(CommonConstants.HOST + CommonConstants.URL_RESERVE_NAME_INTRO); WebDriverWait wait2 = new WebDriverWait(driver, 5); wait2.until(ExpectedConditions.elementToBeClickable(By.xpath(ReserveNameElement.INTRO_BUTTON_CANCEL))); driver.findElement(By.xpath(ReserveNameElement.INTRO_RADIO_RESERVE_NAME)).click(); // driver.findElement(By.xpath(ReserveNameElement.INTRO_SELECT_COMPANY_TYPE)).sendKeys("Incorp"); Select dropdown = new Select(driver.findElement(By.xpath(ReserveNameElement.INTRO_SELECT_COMPANY_TYPE))); dropdown.selectByVisibleText("Incorporated"); driver.findElement(By.xpath(ReserveNameElement.INTRO_BUTTON_NEXT)).click(); // WebDriver driver = new FirefoxDriver(); // LoginTester login = new LoginTester(driver); // IncorporatedTester tester = new IncorporatedTester(driver); // // login.start(); // //Maximize the browser // driver.manage().window().maximize(); // tester.start(); // tester.stop(); // // Click on Math Calculators // driver.findElement(By.xpath(".//*[@id='hcalc']/table/tbody/tr/td[2]/div[3]/a")).click(); // // // Click on Percent Calculators // driver.findElement(By.xpath(".//*[@id='content']/ul[1]/li[3]/a")).click(); // // // Enter value 10 in the first number of the percent Calculator // driver.findElement(By.id("cpar1")).sendKeys(data.getNumberText(2)); // // // Enter value 50 in the second number of the percent Calculator // driver.findElement(By.id("cpar2")).sendKeys(data.getNumberText(2)); // // // Click Calculate Button // driver.findElement(By.xpath(".//*[@id='content']/table[1]/tbody/tr[2]/td/input[2]")).click(); // // // // Get the Result Text based on its xpath // String result = driver.findElement(By.xpath(".//*[@id='content']/p[2]/font/b")).getText(); // // // // Print a Log In message to the screen // System.out.println(" The Result is " + result); //Close the Browser. driver.close(); }
From source file:cls.ui.model.selenium.carDealerManage.BasicInfoPage.java
public void selectCarDealerType(String carDealerTypeString) throws Throwable { WebElement carDealerType = driver.findElement(By.xpath( "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[2]/fieldset/div[1]/div/select")); Select mySelect = new Select(carDealerType); mySelect.selectByVisibleText(carDealerTypeString); }
From source file:cls.ui.model.selenium.carDealerManage.BasicInfoPage.java
public void selectRecommendName(String recommendName) throws Throwable { WebElement recommendNameSelect = driver.findElement(By.id("employDealerId")); Select mySelect = new Select(recommendNameSelect); mySelect.selectByVisibleText(recommendName); }
From source file:cls.ui.model.selenium.carDealerManage.BasicInfoPage.java
public void selectProvince(String province) throws Throwable { WebElement provinceSelect = driver.findElement(By.xpath( "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[4]/div[1]/div/select")); Select mySelect = new Select(provinceSelect); mySelect.selectByVisibleText(province); Thread.sleep(1000);/*from w ww . j av a 2s .c om*/ }
From source file:cls.ui.model.selenium.carDealerManage.BasicInfoPage.java
public void selectCity(String city) throws Throwable { WebElement citySelect = driver.findElement(By.xpath( "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[4]/div[2]/div/select")); Select mySelect = new Select(citySelect); mySelect.selectByVisibleText(city); Thread.sleep(1000);//from ww w . j av a2s. c o m }
From source file:cls.ui.model.selenium.carDealerManage.BasicInfoPage.java
public void selectArea(String area) throws Throwable { WebElement areaSelect = driver.findElement(By.xpath( "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[4]/div[3]/div/select")); Select mySelect = new Select(areaSelect); mySelect.selectByVisibleText(area); }