List of usage examples for org.openqa.selenium WebElement getAttribute
String getAttribute(String name);
From source file:com.gorillalogic.agents.html.automators.ItemSelectorAutomator.java
License:Open Source License
protected String select(Command command) { List<String> selected = command.getArgs(); int successCount = 0; // We may want to deselect all if we do not have deselect action if (getSelect().isMultiple()) { getSelect().deselectAll();//from w w w . ja va2 s .c o m } int i = 0; for (WebElement option : getSelect().getOptions()) { for (String selection : selected) { if (selection.equals(option.getText()) || selection.equals(option.getAttribute("value"))) { getSelect().selectByIndex(i); successCount++; } } i++; } if (successCount == command.getArgs().size()) return null; throw new IllegalArgumentException("Invalid selection value '" + command.getArgsAsString() + "'"); }
From source file:com.gumtreescraper.scraper.GumtreeScraper.java
public void scrapeWithClick(List<Gumtree> gumtrees, String url) { openSite(url);//from ww w. ja v a 2 s . c o m waitForPageToLoad(); do { List<WebElement> gumtreeAds = (new WebDriverWait(this.webDriver, getTimeout())) .until(ExpectedConditions.presenceOfAllElementsLocatedBy( By.xpath("//ul[@id='srchrslt-adtable']/li//h6[@class='rs-ad-title']/a"))); for (WebElement ad : gumtreeAds) { // String adUrl = (new WebDriverWait(this.webDriver, 15)) // .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//h6[@class='rs-ad-title']/a"))).getAttribute("href"); // String adUrl = ad.findElement(By.xpath("//h6[@class='rs-ad-title']/a")).getAttribute("href"); String adUrl = ad.getAttribute("href"); Gumtree gumtree = new Gumtree(); gumtree.setUrl(adUrl); gumtrees.add(gumtree); } List<WebElement> nextElements = webDriver.findElements(By.xpath("//a[@class='rs-paginator-btn next']")); if (nextElements.isEmpty()) { // no more next page break; } nextElements.get(0).click(); try { Thread.sleep(5000); } catch (InterruptedException ex) { Logger.getLogger(GumtreeScraper.class.getName()).log(Level.SEVERE, null, ex); } } while (true); }
From source file:com.gumtreescraper.scraper.GumtreeScraper.java
public void scrape(List<Gumtree> gumtrees, String url) { // get total page int totalPage = getTotalPage(url); for (int i = 1; i <= totalPage; i++) { String newUrl = buildPageUrl(url, i); // openSiteWithoutTimeout(newUrl); openSite(newUrl);// w w w . j a va2s .c om waitForPageToLoad(); if (i == 1) { try { Thread.sleep(20 * 1000); } catch (InterruptedException ex) { Logger.getLogger(GumtreeScraper.class.getName()).log(Level.SEVERE, null, ex); } } // List<WebElement> gumtreeAds = (new WebDriverWait(this.webDriver, 15)) // .until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//ul[@id='srchrslt-adtable']/li"))); List<WebElement> gumtreeAds = (new WebDriverWait(this.webDriver, SPECIAL_TIMEOUT)) .until(ExpectedConditions.presenceOfAllElementsLocatedBy( By.xpath("//ul[@id='srchrslt-adtable']/li//h6[@class='rs-ad-title']/a"))); for (WebElement ad : gumtreeAds) { // (new WebDriverWait(this.webDriver, 15)) // .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//h6[@class='rs-ad-title']/a"))); try { // String adUrl = ad.findElement(By.xpath("//h6[@class='rs-ad-title']/a")).getAttribute("href"); String adUrl = ad.getAttribute("href"); Gumtree gumtree = new Gumtree(); gumtree.setUrl(adUrl); gumtrees.add(gumtree); } catch (StaleElementReferenceException ex) { ex.printStackTrace(); String adUrl = ad.findElement(By.xpath("//h6[@class='rs-ad-title']/a")).getAttribute("href"); Gumtree gumtree = new Gumtree(); gumtree.setUrl(adUrl); gumtrees.add(gumtree); } } // List<WebElement> nextElements = webDriver.findElements(By.xpath("//a[@class='rs-paginator-btn next']")); // if (nextElements.isEmpty()) { // no more next page // break; // } // // nextElements.get(0).click(); } // List<WebElement> lastPageElements = webDriver.findElements(By.xpath("//a[@class='rs-paginator-btn last']")); // if (lastPageElements.isEmpty()) { // 1 page only // return; // } // // do { // List<WebElement> gumtreeAds = (new WebDriverWait(this.webDriver, 15)) // .until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//ul[@id='srchrslt-adtable']/li"))); // // for (WebElement ad : gumtreeAds) { // String adUrl = (new WebDriverWait(this.webDriver, 15)) // .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//h6[@class='rs-ad-title']/a"))).getAttribute("href"); //// String adUrl = ad.findElement(By.xpath("//h6[@class='rs-ad-title']/a")).getAttribute("href"); // Gumtree gumtree = new Gumtree(); // gumtree.setUrl(adUrl); // gumtrees.add(gumtree); // } // // List<WebElement> nextElements = webDriver.findElements(By.xpath("//a[@class='rs-paginator-btn next']")); // if (nextElements.isEmpty()) { // no more next page // break; // } // // nextElements.get(0).click(); // //// scrape(gumtrees, nextPageUrl); // // } while(true); }
From source file:com.hack23.cia.systemintegrationtest.UserPageVisit.java
License:Apache License
/** * Gets the action ids by.//from www .ja v a2 s.c o m * * @param action * the action * @return the action ids by */ public List<String> getActionIdsBy(final ViewAction action) { final List<String> idList = new ArrayList<>(); final String xPath = "//*[contains(@id,'" + action.name() + "')]"; for (final WebElement webElement : driver.findElements(By.xpath(xPath))) { idList.add(webElement.getAttribute("id")); } return idList; }
From source file:com.hotwire.selenium.angular.AngularHotelResultsPage.java
License:Open Source License
public ArrayList<String> getAllResultsStarRatings() { ArrayList<String> starRatings = new ArrayList<String>(); if (0 == resultsList.size()) { throw new ZeroResultsTestException("Angular hotel results page: 0 results returned."); }//from w ww . java2s.c o m for (WebElement result : getWebDriver() .findElements(By.cssSelector(RESULTS_LIST + " a img[data-bdd='starRating']"))) { starRatings.add(result.getAttribute("data-star")); } //starRatings.remove(0); return starRatings; }
From source file:com.hotwire.selenium.bex.BexAbstractPage.java
License:Open Source License
protected void selectValueByIndex(String selectPath, int index, int timeOut) { List<WebElement> options = findMany(selectPath + " option", timeOut); String indexStr = String.valueOf(index); for (WebElement option : options) { if (option.getAttribute("index").equals(indexStr)) { option.click();//from w w w .j a va2s. c om break; } } }
From source file:com.hotwire.selenium.desktop.account.AccountEmailSubscriptionsFormFragment.java
License:Open Source License
private boolean isSubscribed(WebElement row) { WebElement input = getSubscribeOrUnsubsribeButton(row, SUBSCRIBE_CLASS); String checked = input.getAttribute("checked"); return StringUtils.equals(checked, "true"); }
From source file:com.hotwire.selenium.desktop.account.AccountTripsPage.java
License:Open Source License
/** * Search for a trip with defined params. * * @param tripType String - {car, hotel, air} * @param location String//from ww w .j a v a 2 s . com * @param tripStatus String status of a trip {booked, reserved, cancelled} * @param formattedStartDate String formatted pick up date * @param formattedEndDate String formatted drop off date * @return WebElement if trip was found or null */ public WebElement hasRecentlyBookedTripDetails(String tripType, String location, String tripStatus, String formattedStartDate, String formattedEndDate) { LOGGER.info("Search for a " + tripType + " trip in " + location + " (" + formattedStartDate + " - " + formattedEndDate + ")"); List<WebElement> trips = getWebDriver() .findElements(By.cssSelector("ul.tripsList li div.trips div." + tripType + "Trip")); if (trips.isEmpty()) { LOGGER.info( "hasRecentlyBookedTripDetails() trips list is empty. Need a wait for list item(s) visiblity"); } for (WebElement trip : trips) { try { if (trip.getAttribute("class").contains("collapsed")) { LOGGER.info("Expand trip details"); trip.findElement(By.cssSelector("div.arrow a")).click(); } trip.findElement( By.xpath(".//a[contains(@class, 'tripDetails')][contains(text(), '" + location + "')]")); trip.findElement(By.xpath(".//div[contains(@class, 'dates')]//label[contains(text(), '" + formattedStartDate + " - " + formattedEndDate + "')]")); trip.findElement(By.xpath(".//div[contains(@class, 'actions')]//div[contains(text(), '" + TripTypes.valueOf(tripStatus.toUpperCase()) + "')]")); return trip; } catch (Exception e) { // no action } } LOGGER.info(tripType + " trip in " + location + " (" + formattedStartDate + " - " + formattedEndDate + ")" + " has not " + TripTypes.valueOf(tripStatus.toUpperCase())); return null; }
From source file:com.hotwire.selenium.desktop.account.RegisterNewUserPage.java
License:Open Source License
private Boolean isCheckBoxChecked(WebElement checkBox) { try {//from w w w . j a v a2 s. com return checkBox.getAttribute("checked").equals("true"); } catch (NullPointerException e) { return false; } }
From source file:com.hotwire.selenium.desktop.common.billing.HotelBillingPage.java
License:Open Source License
public HotelBillingPage setProvince(String province) { boolean availableElement = false; for (WebElement element : getWebDriver() .findElements(By.cssSelector("select[name='paymentInfoModel.newCreditCard.province']"))) { if (element.isDisplayed()) { Select select = new Select(element); // If province is a number, select by index. If not select by value of province. try { select.selectByIndex(Integer.parseInt(province)); availableElement = true; break; } catch (NumberFormatException e) { select.selectByValue(province); availableElement = true; break; }/* w w w . j a v a2 s . c om*/ } LOGGER.info("Select Province class: " + element.getAttribute("class") + " not displayed."); } if (!availableElement) { LOGGER.info("No selectable province elements visible for use."); } return this; }