List of usage examples for org.openqa.selenium By name
public static By name(String name)
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 v a2s .co 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 v a2s. co m*/ 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 va2s . c o 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 {// w w w . j a v a 2 s . c o 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 {/*from w w w.java 2 s . co 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(); } }
From source file:com.asiainfo.tfsPlatform.web.functional.gui.TaskGuiFT.java
License:Apache License
/** * //?/.// ww w .ja v a2s . c o m */ @Test @Category(Smoke.class) public void crudTask() { s.open("/task/"); // create s.click(By.linkText("")); TaskDto task = TaskData.randomTask(); s.type(By.id("task_title"), task.getTitle()); s.click(By.id("submit_btn")); assertThat(s.isTextPresent("?")).isTrue(); // update s.click(By.linkText(task.getTitle())); assertThat(s.getValue(By.id("task_title"))).isEqualTo(task.getTitle()); String newTitle = TaskData.randomTitle(); s.type(By.id("task_title"), newTitle); s.click(By.id("submit_btn")); assertThat(s.isTextPresent("?")).isTrue(); // search s.type(By.name("search_LIKE_title"), newTitle); s.click(By.id("search_btn")); assertThat(s.getTable(By.id("contentTable"), 0, 0)).isEqualTo(newTitle); // delete s.click(By.linkText("")); assertThat(s.isTextPresent("?")).as("??").isTrue(); }
From source file:com.atanas.kanchev.testframework.core.tests.handlers.FinderTest.java
License:Apache License
@Test public void elementByTest() throws Exception { goTo("https://www.google.co.uk/"); find().elementBy(By.name("btnK")); }
From source file:com.autocognite.appium.lib.base.AbstractAppiumUiDriver.java
License:Apache License
public By getFinderType(String identifier, String idValue) throws Exception { By findBy = null;/* w w w . j ava 2s. c om*/ MobileWebIdentifyBy idType = null; try { idType = MobileWebIdentifyBy.valueOf(identifier.toUpperCase()); } catch (Throwable e) { throwUnsupportedIndentifierException(this.getName(), "getFinderType", identifier); } switch (identifier.toUpperCase()) { case "ID": findBy = By.id(idValue); break; case "NAME": findBy = By.name(idValue); break; case "CLASS": findBy = By.className(idValue); break; case "LINK_TEXT": findBy = By.linkText(idValue); break; case "PARTIAL_LINK_TEXT": findBy = By.partialLinkText(idValue); break; case "XPATH": findBy = By.xpath(idValue); break; case "CSS": findBy = By.cssSelector(idValue); break; case "TAG": findBy = By.tagName(idValue); break; } return findBy; }
From source file:com.autocognite.selenium.lib.SeleniumWebUiDriver.java
License:Apache License
@SuppressWarnings("incomplete-switch") public By getFinderType(String identifier, String idValue) throws Exception { By findBy = null;/*from ww w. j a v a 2s. c o m*/ WebIdentifyBy idType = null; try { idType = WebIdentifyBy.valueOf(identifier.toUpperCase()); } catch (Throwable e) { throwUnsupportedIndentifierException(Configurator.getComponentName("WEBDRIVER_AUTOMATOR"), "getFinderType", identifier); } switch (idType) { case ID: findBy = By.id(idValue); break; case NAME: findBy = By.name(idValue); break; case CLASS: findBy = By.className(idValue); break; case LINK_TEXT: findBy = By.linkText(idValue); break; case PARTIAL_LINK_TEXT: findBy = By.partialLinkText(idValue); break; case XPATH: findBy = By.xpath(idValue); break; case CSS: findBy = By.cssSelector(idValue); break; case TAG: findBy = By.tagName(idValue); break; } return findBy; }
From source file:com.axatrikx.webdriver.ElementHelper.java
License:Apache License
private By parseLocator(String locator) { String locValue;//from w w w .j ava 2s . c o m By byElement = null; if (locator.toLowerCase().startsWith("id=")) { locValue = locator.substring(3); byElement = By.id(locValue); } else if (locator.toLowerCase().startsWith("name=")) { locValue = locator.substring(5); byElement = By.name(locValue); } else if (locator.toLowerCase().startsWith("class=")) { locValue = locator.substring(6); byElement = By.className(locValue); } else if (locator.toLowerCase().startsWith("css=")) { locValue = locator.substring(4); byElement = By.cssSelector(locValue); } else if (locator.toLowerCase().startsWith("xpath=")) { locValue = locator.substring(6); byElement = By.xpath(locValue); } else if (locator.toLowerCase().startsWith("classname=")) { locValue = locator.substring(10); byElement = By.className(locValue); } else if (locator.toLowerCase().startsWith("tagname=")) { locValue = locator.substring(8); byElement = By.tagName(locValue); } else if (locator.toLowerCase().startsWith("link=")) { locValue = locator.substring(5); byElement = By.linkText(locValue); } else if (locator.toLowerCase().startsWith("partiallinktext=")) { locValue = locator.substring(16); byElement = By.partialLinkText(locValue); } else { // set default to id byElement = By.id(locator); } return byElement; }