List of usage examples for org.openqa.selenium.support.ui Select selectByIndex
@Override public void selectByIndex(int index)
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 . java 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"); // }
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/* w w w. j av a2 s. 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/* 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 ww w . ja v a 2 s . com } 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:at.ac.tuwien.big.testsuite.impl.selenium.RegisterTest.java
License:Apache License
/** * Fills out the registration form, submit it and wait for the response * * @param firstname//from ww w . ja v a 2 s. c o m * @param lastName * @param birthdate * @param sex * @param username * @param password */ private void doRegistration(String firstname, String lastName, String birthdate, int sex, String username, String password) { String firstnameId = getPrefixedId("firstname"); driver.findElement(By.id(firstnameId)).sendKeys(firstname); String lastnameId = getPrefixedId("lastname"); driver.findElement(By.id(lastnameId)).sendKeys(lastName); String birthdateId = ID_PREFIXES[0] + BIRTHDAY_IDS[0]; for (String bId : BIRTHDAY_IDS) { for (String tmpPrefix : ID_PREFIXES) { if (exists(By.id(tmpPrefix + bId))) { birthdateId = tmpPrefix + bId; break; } } } driver.findElement(By.id(birthdateId)).sendKeys(birthdate); String sexId = getPrefixedId("sex"); Select dropDown = new Select(driver.findElement(By.id(sexId))); dropDown.selectByIndex(sex); String usernameId = getPrefixedId("username"); driver.findElement(By.id(usernameId)).sendKeys(username); String passwordId = getPrefixedId("password"); driver.findElement(By.id(passwordId)).sendKeys(password); String submitId = getPrefixedId("submit"); driver.findElement(By.id(submitId)).click(); wait(200); waitForJQuery(driver); }
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 {/*from w w w . j a va2 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.amolik.scrapers.OdishaRationCardScraper.java
public static Select getRefreshedBlockSelect(WebDriver driver, int districtIndex) { Select districtSelect = new Select(driver.findElement(By.name(Constants.DDL_DISTRICT))); districtSelect.selectByIndex(districtIndex); if (logger.isDebugEnabled()) { logger.debug("getRefreshedBlockSelect(WebDriver, int) - selected district=" + districtSelect.getAllSelectedOptions().toString()); //$NON-NLS-1$ }//from w w w .j a va 2 s .com waitForBlock(driver, getDistrictValueFromIndex(districtIndex), Constants.SELECT_0); Select blockSelect = new Select(driver.findElement(By.name(Constants.DDL_BLOCK))); return blockSelect; }
From source file:com.amolik.scrapers.OdishaRationCardScraper.java
public static void processBlock(WebDriver driver, int districtIndex, int blockIndex, String blockValue, String blockName, ArrayList<OdishaRationCardBean> beanList) { // Select block based upon index Select blockSelect = getRefreshedBlockSelect(driver, districtIndex); blockSelect.selectByIndex(blockIndex); String districtName = districtsNameList.get(districtIndex); // // Create new Directory if not exists // String excelDestDirName = AmolikProperties.getProperty("odisha_ration.excelOutputDir") // +System.getProperty("file.separator") // +districtName; ////from w w w.j a v a2 s . co m // new File(excelDestDirName).mkdirs(); // // String excelDestFileName = excelDestDirName // +Constants.BACK_SLASH+blockName+".xlsx"; driver.findElement(By.name(Constants.BTN_SHOW)).click(); waitForSubmit(driver, Constants.NO_DETAILS_FOUND, blockValue); int rowCount = driver.findElements(By.xpath("//table[@id='gvDist']/tbody/tr")).size(); if (logger.isInfoEnabled()) { logger.info(districtIndex + "|" + districtName + "|" + blockIndex + "|" + blockName + "| recordCount=" + (rowCount - 3)); //$NON-NLS-1$ } // Remove during production //rowCount=7; if (rowCount > 2) { for (int i = 2; i < rowCount - 1; i++) { List<WebElement> columns = driver .findElements(By.xpath("//table[@id='gvDist']/tbody/tr[" + (i + 1) + "]/td")); StringBuffer columnBuffer = new StringBuffer(); // Temporary select max columns to process int columnToProcess = 5; columnToProcess = Math.min(columnToProcess, columns.size()); OdishaRationCardBean bean = new OdishaRationCardBean(); setBean(columns, columnToProcess, bean); beanList.add(bean); } } }
From source file:com.arifnazarpurwandaru.selenium.MainFrame.java
private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed try {//from w w w. j av a 2 s .co m // MarionetteDriverManager.getInstance().setup(); System.out.println("Mulai Pencarian..."); // Runtime.getRuntime().exec("TASKKILL /F /IM Firefox.exe"); // Runtime.getRuntime().exec("TASKKILL /F /IM iexplore.exe"); // Runtime.getRuntime().exec("TASKKILL /F /IM iexplore.exe"); WebDriver driver = null; String kereta = ((ComboItem) comboKereta.getSelectedItem()).getValue(); //use proxy if (radioUseProxy.isSelected()) { String proxyHost = hostProxy.getText() + ":" + portProxy.getText(); Proxy proxy = new Proxy(); proxy.setHttpProxy(proxyHost); proxy.setSslProxy(proxyHost); proxy.setFtpProxy(proxyHost); proxy.setSocksUsername(usernameProxy.getText()); proxy.setSocksPassword(new String(passwordProxy.getPassword())); DesiredCapabilities cap = new DesiredCapabilities(); cap.setCapability(CapabilityType.PROXY, proxy); driver = new ChromeDriver(cap); } else { // driver = new MarionetteDriver(); driver = new ChromeDriver(); } // hmin = Integer.valueOf(args[0]).intValue(); ComboItem link = (ComboItem) comboLink.getSelectedItem(); driver.get(link.getValue()); List<WebElement> list = null; int counter = 1; boolean keeploop = true; while (/**list==null || list.size() == 0**/ keeploop) { try { Select selectTgl = new Select(driver.findElement(By.name("tanggal"))); selectTgl.selectByIndex(comboTanggal.getSelectedIndex()); ComboItem stFrom = (ComboItem) comboStBerangkat.getSelectedItem(); Select selectFrom = new Select(driver.findElement(By.name("origination"))); selectFrom.selectByValue(stFrom.getValue()); ComboItem stTo = (ComboItem) comboStTujuan.getSelectedItem(); Select selectTo = new Select(driver.findElement(By.name("destination"))); selectTo.selectByValue(stTo.getValue()); Select selectAdult = new Select(driver.findElement(By.name("adult"))); selectAdult.selectByValue("1"); WebElement element = driver.findElement(By.name("Submit")); element.click(); // Thread.sleep(1000); //tunggu sampe page ready, nandainnya kalo element div dengan css class "itReservationContent" muncul WebElement elementForWait = (new WebDriverWait(driver, 1)).until( ExpectedConditions.visibilityOfElementLocated(By.className("itReservationContent"))); //end wait list = driver.findElements(By.className("itButton")); if (list != null && list.size() > 0) { List<WebElement> listForm = driver.findElements(By.tagName("form")); for (WebElement form : listForm) { List<WebElement> listInput = form.findElements(By.tagName("input")); for (WebElement input : listInput) { if (input.getAttribute("value").equalsIgnoreCase(kereta)) { WebElement btn = form.findElement(By.className("itButton")); btn.click(); System.out.println("========================>KLIK BOOKING"); keeploop = false; throw new KlikException("BerhasilKlik"); } } } } System.out.println("==========================> looping ke: " + counter); counter++; } catch (KlikException ke) { System.out.println("================> Masuk Klik Exception"); keeploop = false; break; } catch (Exception e) { e.printStackTrace(); System.out.println("===================> Reconecting..." + link.getValue()); driver.get(link.getValue()); } } // System.out.println("ada keretaaaaaa: "+list.size()); List<WebElement> listInput = driver.findElements(By.tagName("input")); for (WebElement input : listInput) { if (input.getAttribute("type").equals("checkbox")) { input.click(); break; } } WebElement lanjut = driver.findElement(By.cssSelector("input[type='submit'][name='booking']")); lanjut.click(); //Ngisi Tikete //Nunggu disit //tunggu sampe page ready, nandainnya kalo element div dengan css class "txt_first_name_adult_1" muncul WebElement elementForWait = (new WebDriverWait(driver, 3)) .until(ExpectedConditions.visibilityOfElementLocated(By.id("txt_first_name_adult_1"))); //end wait WebElement namaPenumpang = driver.findElement(By.id("txt_first_name_adult_1")); WebElement ktp = driver.findElement(By.id("txt_passport_1")); WebElement contactName = driver.findElement(By.id("txt_contact_first_name")); WebElement contactEmail = driver.findElement(By.id("txt_contact_email")); WebElement contactPhone = driver.findElement(By.id("txt_contact_phone")); WebElement contactAddress = driver.findElement(By.id("txt_contact_home_address")); namaPenumpang.sendKeys(txtNamaPenumpang.getText()); ktp.sendKeys(txtNoKTP.getText()); contactName.sendKeys(txtNamaPenumpang.getText()); contactEmail.sendKeys(txtEmail.getText()); contactPhone.sendKeys(txtNoTelp.getText()); contactAddress.sendKeys(txtAlamat.getText()); playSound(); JOptionPane.showMessageDialog(rootPane, "Booking sudah tersedia, Silakan inputkan Captcha!! Dan lanjutkan secara manual", "Informasi", JOptionPane.INFORMATION_MESSAGE); this.setAlwaysOnTop(true); System.out.println("DONE"); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.arifnazarpurwandaru.selenium.MainFrame.java
private void btnSearchBiasaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchBiasaActionPerformed try {/*w ww . j a v a 2s. c o m*/ Runtime.getRuntime().exec("TASKKILL /F /IM Firefox.exe"); Runtime.getRuntime().exec("TASKKILL /F /IM iexplore.exe"); WebDriver driver = null; //use proxy if (radioUseProxy.isSelected()) { String proxyHost = hostProxy.getText() + ":" + portProxy.getText(); Proxy proxy = new Proxy(); proxy.setHttpProxy(proxyHost); proxy.setSslProxy(proxyHost); proxy.setFtpProxy(proxyHost); proxy.setSocksUsername(usernameProxy.getText()); proxy.setSocksPassword(new String(passwordProxy.getPassword())); DesiredCapabilities cap = new DesiredCapabilities(); cap.setCapability(CapabilityType.PROXY, proxy); driver = new ChromeDriver(cap); } else { driver = new ChromeDriver(); } ComboItem link = (ComboItem) comboLink.getSelectedItem(); driver.get(link.getValue()); List<WebElement> list = null; int counter = 1; while (list == null || list.size() == 0) { try { Select selectTgl = new Select(driver.findElement(By.name("tanggal"))); selectTgl.selectByIndex(comboTanggalBiasa.getSelectedIndex()); ComboItem ck = (ComboItem) comboStBerangkatBiasa.getSelectedItem(); Select selectFrom = new Select(driver.findElement(By.name("origination"))); selectFrom.selectByValue(ck.getValue()); ComboItem ct = (ComboItem) comboStTujuanBiasa.getSelectedItem(); Select selectTo = new Select(driver.findElement(By.name("destination"))); selectTo.selectByValue(ct.getValue()); Select selectAdult = new Select(driver.findElement(By.name("adult"))); selectAdult.selectByValue("1"); WebElement element = driver.findElement(By.name("Submit")); element.click(); //tunggu sampe page ready, nandainnya kalo element div dengan css class "itReservationContent" muncul WebElement elementForWait = (new WebDriverWait(driver, 1)).until( ExpectedConditions.visibilityOfElementLocated(By.className("itReservationContent"))); //end wait list = driver.findElements(By.className("itButton")); System.out.println("==========================> looping ke: " + counter); counter++; } catch (Exception e) { System.out.println("===================> Reconecting..." + link.getValue()); driver.get(link.getValue()); } } System.out.println("ada keretaaaaaa: " + list.size()); System.out.println("DONE"); } catch (Exception e) { e.printStackTrace(); } }