List of usage examples for org.openqa.selenium.support.ui Select getOptions
@Override
public List<WebElement> getOptions()
From source file:administrationedit.addCompany.java
public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe"); driver = new ChromeDriver(); WebDriverWait wait = new WebDriverWait(driver, 3); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); Random r = new Random(); Faker faker = new Faker(); driver.get("https://goldfish.dev.hexis.hr/demo/en/administration/user/updateCompanySettings"); adminLogin login = new adminLogin(driver); login.loginToAdmin("demo", "demo"); // Input name String nameComp = faker.company().name(); driver.findElement(By.id("name")).clear(); driver.findElement(By.id("name")).sendKeys(nameComp); // Input address String addressComp = faker.address().fullAddress(); driver.findElement(By.id("address")).clear(); driver.findElement(By.id("address")).sendKeys(addressComp); // Input city String cityComp = faker.address().city(); driver.findElement(By.id("city")).clear(); driver.findElement(By.id("city")).sendKeys(cityComp); // Input postal code String postalCodeComp = faker.address().zipCode(); driver.findElement(By.id("postalCode")).clear(); driver.findElement(By.id("postalCode")).sendKeys(postalCodeComp); // Country/*ww w. j a va 2s. c om*/ Select countryComp = new Select(driver.findElement(By.id("country"))); int coutryCompInt = r.nextInt(countryComp.getOptions().size()) + 1; countryComp.selectByIndex(coutryCompInt); // Email String emailComp = faker.internet().emailAddress(); driver.findElement(By.id("email")).clear(); driver.findElement(By.id("email")).sendKeys(emailComp); // Phone String phoneComp = faker.phoneNumber().phoneNumber().replaceAll("\\D", ""); driver.findElement(By.id("phone")).clear(); driver.findElement(By.id("phone")).sendKeys(phoneComp); // Mobile String mobileComp = faker.phoneNumber().cellPhone().replaceAll("\\D", ""); driver.findElement(By.id("mobilePhone")).clear(); driver.findElement(By.id("mobilePhone")).sendKeys(mobileComp); // Fax String faxComp = faker.phoneNumber().phoneNumber().replaceAll("\\D", ""); driver.findElement(By.id("fax")).clear(); driver.findElement(By.id("fax")).sendKeys(faxComp); // OIB String oibComp = faker.idNumber().validSvSeSsn(); driver.findElement(By.id("oib")).clear(); driver.findElement(By.id("oib")).sendKeys(oibComp); // VatID String vatComp = faker.idNumber().validSvSeSsn(); driver.findElement(By.id("vatId")).clear(); driver.findElement(By.id("vatId")).sendKeys(vatComp); // Id code String idCodeComp = faker.idNumber().valid(); driver.findElement(By.id("idCode")).clear(); driver.findElement(By.id("idCode")).sendKeys(idCodeComp); // MBS String mbsComp = faker.number().digits(15); driver.findElement(By.id("mbs")).clear(); driver.findElement(By.id("mbs")).sendKeys(mbsComp); // ID number String idNumComp = faker.number().digits(15); driver.findElement(By.id("identificationNumber")).clear(); driver.findElement(By.id("identificationNumber")).sendKeys(idNumComp); // IBAN String ibanComp = faker.finance().iban(); driver.findElement(By.id("iban")).clear(); driver.findElement(By.id("iban")).sendKeys(ibanComp); // Swift String swiftComp = faker.finance().bic(); driver.findElement(By.id("swift")).clear(); driver.findElement(By.id("swift")).sendKeys(swiftComp); //Bank name String bankNameComp = faker.name().name(); driver.findElement(By.id("bankName")).clear(); driver.findElement(By.id("bankName")).sendKeys(bankNameComp); // Bank address String bankAddressComp = faker.address().fullAddress(); driver.findElement(By.id("bankAddress")).clear(); driver.findElement(By.id("bankAddress")).sendKeys(bankAddressComp); // Bank city String bankCityComp = faker.address().city(); driver.findElement(By.id("bankCity")).clear(); driver.findElement(By.id("bankCity")).sendKeys(bankCityComp); // Bank postal code String bankPostalCodeComp = faker.address().zipCode(); driver.findElement(By.id("bankPostalCode")).clear(); driver.findElement(By.id("bankPostalCode")).sendKeys(bankPostalCodeComp); // Bank country Select bankCountryComp = new Select(driver.findElement(By.id("bankCountry"))); int bankCoutryCompInt = r.nextInt(bankCountryComp.getOptions().size()) + 1; bankCountryComp.selectByIndex(bankCoutryCompInt); // Social String socialTW = faker.internet().url(); String socialFB = faker.internet().url(); driver.findElement(By.id("twitterUsername")).clear(); driver.findElement(By.id("facebookID")).clear(); driver.findElement(By.id("twitterUsername")).sendKeys(socialTW); driver.findElement(By.id("facebookID")).sendKeys(socialFB); // SAVE driver.findElement( By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[2]/div[26]/div/button")) .click(); }
From source file:administrationedit.addOffice.java
public static void main(String[] args) throws InterruptedException { System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe"); driver = new ChromeDriver(); WebDriverWait wait = new WebDriverWait(driver, 3); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); String[] city = { "Rijeka", "Pula", "Pore?", "Rovinj", "Umag", "Novigrad", "Vrsar", "Pazin", "Motovun", "Medulin", "Faana", "Vodnjan", "Opatija", "Krk", "Punat", "Baka", "Njivice", "Labin", "Rabac", "Plomin", "I?ii", "Ika", "Malinska", "Njivice", "Omialj", "Dramalj", "Crikvenica", "Selce", "Cres", "Rab", "Novi Vinodolski", "Povile", "iii", "Vodice", "Pinezii", "Lovran", "Medveja", "shanghai", "sao paulo", "kinshasa", "cairo", "peking", "london", "bogota", "dhaka", "rio de janeiro", "santiago", "toronto", "sydney", "wuhan", "chongqing", "xian", "chengdu", "alexandria", "tianjin", "melbourne", "abidjan", "shenyang", "berlin", "montreal", "harbin", "guangzhou", "madrid", "nanjing", "kabul", "luanda", "addis abeba", "taiyuan", "salvador", "changchun", "gizeh", "fortaleza", "cali", "belo horizonte", "brasilia", "santo domingo", "paris", "jinan", "tangshan", "dalian", "medellin", "algiers", "accra", "guayaquil", "jilin", "hangzhou", "nanchang", "conakry", "brisbane", "vancouver", "minsk", "hamburg", "curitiba", "qingdao", "manaus", "xinyang", "barcelona", "vienna", "urumqi", "recife", "kumasi", "perth", "cordoba", "lanzhou", "belem", "fushun", "quito", "luoyang", "hefei", "barranquilla", "lubumbashi", "porto alegre", "handan", "suzhou", "khulna", "douala", "yaounde", "munich", "rosario", "anshan", "xuzhou", "fuzhou", "guiyang", "goiania", "guarulhos", "prague", "dubai", "baku", "brazzaville", "wuxi", "yerevan", "copenhagen", "adelaide", "sofia", "datong", "tbilisi", "xianyang", "campinas", "ouagadougou", "huainan", "kunming", "brussels", "shenzhen", "nova iguacu", "rongcheng", "baoding", "benxi", "birmingham", "mendoza", "cologne", "calgary", "maceio", "cartagena", "changzhou", "sao goncalo", "sao luis", "huaibei", "cochabamba", "pingdingshan", "qiqihar", "mbuji-mayi", "ottawa", "wenzhou", "tucuman", "edmonton", "duque de caxias", "la paz", "nanning", "marseille", "anyang", "hohhot", "valencia", "xining", "liuzhou", "natal", "qinhuangdao", "hengyang", "taian", "teresina", "xinxiang", "sao bernardo do campo", "hegang", "campo grande", "athens", "cucuta", "langfang", "ningbo", "yantai", "zhuzhou", "jaboatao", "rajshahi", "sarajevo", "zhangjiakou", "cotonou", "zigong", "fuxin", "liaoyang", "sevilla", "la plata", "bangui", "osasco", "zhangdian", "puyang", "nantong", "mudanjiang", "santo andre", "hamilton", "joao pessoa", "shaoyang", "guilin", "frankfurt", "wahran", "mar del plata", "quebec", "zhanjiang", "zaragoza", "zhenjiang", "winnipeg", "dandong", "shaoguan", "yancheng", "foshan", "contagem", "jibuti", "haikou", "sao jose dos campos", "taizhou", "xingtai", "glasgow", "jinzhou", "abu dhabi", "luancheng", "dortmund", "stuttgart", "yingkou", "zhangzhou", "belfast" }; Random r = new Random(); Faker faker = new Faker(); driver.get("https://goldfish.dev.hexis.hr/demo/en/administration/office/add"); adminLogin login = new adminLogin(driver); login.loginToAdmin("demo", "demo"); // Input name String nameComp = faker.company().name(); driver.findElement(By.id("name")).clear(); driver.findElement(By.id("name")).sendKeys(nameComp); // Input address String addressComp = faker.address().fullAddress(); driver.findElement(By.id("address")).clear(); driver.findElement(By.id("address")).sendKeys(addressComp); // Input city String cityComp = faker.address().city(); driver.findElement(By.id("city")).clear(); driver.findElement(By.id("city")).sendKeys(cityComp); // Input postal code String postalCodeComp = faker.address().zipCode(); driver.findElement(By.id("postalCode")).clear(); driver.findElement(By.id("postalCode")).sendKeys(postalCodeComp); // Country/*from w w w.j a v a 2 s . c o m*/ Select countryComp = new Select(driver.findElement(By.id("country"))); int coutryCompInt = r.nextInt(countryComp.getOptions().size()) + 1; countryComp.selectByIndex(coutryCompInt); // Email String emailComp = faker.internet().emailAddress(); driver.findElement(By.id("email")).clear(); driver.findElement(By.id("email")).sendKeys(emailComp); // Phone String phoneComp = faker.phoneNumber().phoneNumber().replaceAll("\\D", ""); driver.findElement(By.id("phone")).clear(); driver.findElement(By.id("phone")).sendKeys(phoneComp); // Mobile String mobileComp = faker.phoneNumber().cellPhone().replaceAll("\\D", ""); driver.findElement(By.id("mobilePhone")).clear(); driver.findElement(By.id("mobilePhone")).sendKeys(mobileComp); // Fax String faxComp = faker.phoneNumber().phoneNumber().replaceAll("\\D", ""); driver.findElement(By.id("fax")).clear(); driver.findElement(By.id("fax")).sendKeys(faxComp); // Geolocation int cityN = r.nextInt(city.length); driver.findElement(By .xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[2]/div[10]/div[1]/div[1]/input")) .sendKeys(city[cityN]); driver.findElement( By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[2]/div[10]/div[1]/div[1]/a")) .click(); Thread.sleep(3000); // SAVE driver.findElement( By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[2]/div[12]/div/button")) .click(); }
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 w w w . j av a2 s . c o 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:applicationdriverlayer.pageobjects.squash.booking.CourtAndTimeSlotChooserPage.java
License:Apache License
public List<java.time.LocalDate> getAllPossibleBookingDates() { Select dateSelect = new Select(dateDropdown); List<LocalDate> bookingDates = dateSelect.getOptions().stream().map((option) -> { return java.time.LocalDate.parse(option.getText(), DateTimeFormatter.ofPattern("EE, d MMM, yyyy")); }).collect(Collectors.toList()); // Ensure we return the dates in earlier-to-later order Collections.sort(bookingDates, (LocalDate d1, LocalDate d2) -> d1.compareTo(d2)); return bookingDates; }
From source file:br.eti.kinoshita.selenium.util.Utils.java
License:Open Source License
public static Function<WebDriver, Select> presenceOfSelectIndexAvailable(final By locator, final int index) { return new Function<WebDriver, Select>() { public Select apply(WebDriver driver) { WebElement foundElement = driver.findElement(locator); if (foundElement != null) { Select select = new Select(foundElement); if (select.getOptions().size() >= index) { return select; }/* www .j a v a 2 s . c o m*/ } // TBD: or throw NoSuchException... return null; } }; }
From source file:br.eti.kinoshita.selenium.util.Utils.java
License:Open Source License
/** * Wait for determined select index in a select (combo) box in a determined period * /* ww w. jav a 2 s . co m*/ * @param select * @param index * @param timeout */ public static void waitForSelectIndex(Select select, Integer index, Long timeout) { Long end = System.currentTimeMillis() + timeout; while (System.currentTimeMillis() < end) { if (select.getOptions().size() < index) { try { Thread.sleep(1000); } catch (InterruptedException e) { LOGGER.debug(e.getMessage(), e); } } else { break; } } }
From source file:ca.nrc.cadc.search.integration.CAOMSearchFormPage.java
License:Open Source License
int findDataTrainValueIndex(final By menuLocator, final String value, final boolean ignoreCase) throws Exception { final Select selectMenu = new Select(dataTrain.findElement(menuLocator)); final List<WebElement> options = selectMenu.getOptions(); final int optionSize = options.size(); for (int i = 0; i < optionSize; i++) { final WebElement option = options.get(i); final String optionValue = option.getAttribute("value"); if ((ignoreCase && optionValue.equalsIgnoreCase(value)) || optionValue.equals(value)) { return i; }/*from w w w. j a v a 2 s. com*/ } throw new IllegalStateException( "No such element with value '" + value + "' (Case" + (ignoreCase ? " " : " not ") + "ignored)"); }
From source file:com.amolik.scrapers.OdishaRationCardScraper.java
public static void processAllDistricts(WebDriver driver) throws InterruptedException { Select districtSelect = new Select(driver.findElement(By.name(Constants.DDL_DISTRICT))); List<WebElement> districtsList = districtSelect.getOptions(); // Prepare List of names of districts for (WebElement districtElement : districtsList) { districtsNameList.add(districtElement.getText()); }/* w ww. j av a2 s . com*/ int districtSize = districtsList.size(); // Remove this during production //districtSize=2; int startDistrictIndex = new Integer(AmolikProperties.getProperty("odisha_ration.startDistrictIndex")) .intValue(); for (int districtIndex = startDistrictIndex; districtIndex < districtSize; districtIndex++) { processDistrict(driver, districtIndex); //TimeUnit.SECONDS.sleep(3); } }
From source file:com.amolik.scrapers.OdishaRationCardScraper.java
public static void processDistrict(WebDriver driver, int districtIndex) { Select districtSelect = new Select(driver.findElement(By.name(Constants.DDL_DISTRICT))); districtSelect.selectByIndex(districtIndex); try {// ww w .j av a 2 s . c o m TimeUnit.SECONDS.sleep(3); } catch (InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } int blockSize = getRefreshedBlockSelect(driver, districtIndex).getOptions().size(); if (logger.isDebugEnabled()) { logger.debug("processDistrict blockSize=" + blockSize); //$NON-NLS-1$ } // Remove during production //blockSize =2; int startBlockIndex = new Integer(AmolikProperties.getProperty("odisha_ration.startBlockIndex")).intValue(); ArrayList<OdishaRationCardBean> beanList = new ArrayList(); for (int blockIndex = startBlockIndex; blockIndex < blockSize; blockIndex++) { Select blockSelect = getRefreshedBlockSelect(driver, districtIndex); List<WebElement> blocksList = blockSelect.getOptions(); WebElement block = blocksList.get(blockIndex); if (logger.isDebugEnabled()) { logger.debug("processDistrict(WebDriver, int) - block=" + block.getText()); //$NON-NLS-1$ } String blockValue = block.getAttribute(Constants.LOWERCASE_VALUE); if (logger.isDebugEnabled()) { logger.debug("processDistrict(WebDriver, int) - " + districtIndex + "|" + block.getAttribute(Constants.LOWERCASE_VALUE) + "|" + block.getText()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } processBlock(driver, districtIndex, blockIndex, blockValue, block.getText(), beanList); } // Create new Directory if not exists String districtName = districtsNameList.get(districtIndex); String excelDestDirName = AmolikProperties.getProperty("odisha_ration.excelOutputDir"); new File(excelDestDirName).mkdirs(); String excelDestFileName = excelDestDirName + System.getProperty("file.separator") + districtName + excelFileExtension; if (logger.isInfoEnabled()) { logger.info("writing to excel " + districtIndex + "|" + districtName + "| toal recordCount=" + (beanList.size())); } ExcelUtil.generateExcelFromBean(beanList, excelTemplateFileName, excelTemplateFileName, excelDestFileName, "rationCard"); }
From source file:com.autocognite.appium.lib.base.AbstractAppiumUiDriver.java
License:Apache License
public boolean isDropDownSelectedIndex(Select selectElement, int index) { List<WebElement> options = selectElement.getOptions(); return options.get(index).isSelected(); }