Example usage for org.openqa.selenium WebElement getAttribute

List of usage examples for org.openqa.selenium WebElement getAttribute

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement getAttribute.

Prototype

String getAttribute(String name);

Source Link

Document

Get the value of the given attribute of the element.

Usage

From source file:com.induscorp.prime.testing.ui.standard.domobj.RadioButtonGroupValidatorSD.java

License:Open Source License

@Override
public void validateEnabled(int numRetries) {
    List<WebElement> webElems = findElements(numRetries);
    List<String> disabledItems = new LinkedList<String>();
    for (WebElement elem : webElems) {
        if (!elem.isEnabled()) {
            disabledItems.add(elem.getAttribute("value"));
        }// ww w  .  ja va 2  s  .co m
    }
    if (disabledItems.size() > 0) {
        Assert.fail("Radio button group '" + uiObject.getDisplayName()
                + "' is not enabled. It has the following disabled items: " + disabledItems);
    }
}

From source file:com.induscorp.prime.testing.ui.standard.domobj.RadioButtonGroupValidatorSD.java

License:Open Source License

@Override
public void selectOption(String value, String displayValue, int numRetries) {
    List<WebElement> webElems = findElements(numRetries);
    String elemVal;//from w w w  . j  a  va 2  s  .c o m
    for (WebElement elem : webElems) {
        elemVal = elem.getAttribute("value");
        if (elemVal != null && elemVal.equals(value)) {
            elem.click();
            break;
        }
    }

    try {
        validateSelectedOption(value, displayValue, numRetries);
    } catch (Throwable th) {
        Assert.fail("Failed to select option with value '" + displayValue + "' in radio button group '"
                + uiObject.getDisplayName() + "'.");
    }
}

From source file:com.induscorp.prime.testing.ui.standard.domobj.RadioButtonGroupValidatorSD.java

License:Open Source License

@Override
public void validateSelectedOption(String value, String displayValue, int numRetries) {
    List<WebElement> webElems = findElements(numRetries);
    String elemVal;/*from ww w.  j  a  v  a  2 s.c o  m*/
    boolean optionFound = false;
    for (WebElement elem : webElems) {
        elemVal = elem.getAttribute("value");
        if (elemVal != null && elemVal.equals(value) && elem.isSelected()) {
            optionFound = true;
            break;
        }
    }
    Assert.assertTrue(optionFound, "Radio button with value '" + displayValue + "' is not selected.");
}

From source file:com.induscorp.prime.testing.ui.standard.domobj.RadioButtonGroupValidatorSD.java

License:Open Source License

@Override
public void validateNotSelectedOptions(ItemMap<String, String> options, int numRetries) {
    List<WebElement> webElems = findElements(numRetries);
    String elemVal;//w w  w. j  a  va  2s .c om
    LinkedHashMap<String, String> selectedOptions = new LinkedHashMap<String, String>();
    for (String optionValue : options.getItems().keySet()) {
        for (WebElement elem : webElems) {
            elemVal = elem.getAttribute("value");
            if (elemVal != null && elemVal.equals(optionValue) && elem.isSelected()) {
                selectedOptions.put(optionValue, options.getItems().get(optionValue));
            }
        }
    }

    if (selectedOptions.size() > 0) {
        Assert.fail("Radio button group '" + uiObject.getDisplayName()
                + "' has some of the options selected. Selected options: " + selectedOptions);
    }
}

From source file:com.ionidea.RegressionNGA.Tests.util.DriverExtension.java

public String getElementText(WebElement element) {
    return element.getAttribute("innerText");
}

From source file:com.jaeksoft.searchlib.crawler.web.spider.ClickCapture.java

License:Open Source License

private boolean locateAimgClickCapture(WebElement aElement) {
    if (!aElement.isDisplayed())
        return false;
    String ahref = aElement.getAttribute("href");
    List<WebElement> imgElements = aElement.findElements(By.cssSelector("img"));
    if (imgElements == null)
        return false;
    for (WebElement imgElement : imgElements) {
        if (!imgElement.isDisplayed())
            continue;
        imgSrc = imgElement.getAttribute("src");
    }// www.j  a  v a 2  s.  c o m
    anchorHref = ahref;
    return true;
}

From source file:com.jaeksoft.searchlib.crawler.web.spider.ClickCapture.java

License:Open Source License

private boolean locateEmbedClickCapture(List<WebElement> embedElements) throws SearchLibException, IOException {
    if (embedElements == null)
        return false;
    for (WebElement embedElement : embedElements) {
        if (!embedElement.isDisplayed())
            continue;
        embedSrc = embedElement.getAttribute("src");
        String flashVars = embedElement.getAttribute("flashvars");
        if (!StringUtils.isEmpty(flashVars)) {
            try {
                URI uri = new URI(embedSrc);
                flashVars = uri.getQuery();
            } catch (URISyntaxException e) {
                Logging.warn(e);//w  ww. j  ava2 s  .c  o m
            }
        }
        String[] params = StringUtils.split(flashVars, '&');
        Map<String, String> paramMap = new TreeMap<String, String>();
        if (params != null) {
            for (String param : params) {
                String[] keyValue = StringUtils.split(param, '=');
                if (keyValue != null && keyValue.length == 2)
                    paramMap.put(keyValue[0].toLowerCase(), URLDecoder.decode(keyValue[1], "UTF-8"));
            }
        }
        if (selector.flashVarsLink != null)
            anchorHref = paramMap.get(selector.flashVarsLink);
        return true;
    }
    return false;
}

From source file:com.jase.knife.BrowserEmulator.java

License:Apache License

/**
 * Gets the value of an element attribute.
 * @return/*from w  w  w .ja  v  a  2 s  .  co  m*/
 */
public String getAttribute(String xpath, String attribute) {
    WebElement el = browser.findElement(By.xpath(xpath));
    String value = el.getAttribute(attribute);
    return value;
}

From source file:com.java.AppTestType_18_11_2015.java

public void MAXOFFERINSEARCHRESULTSPAGE(WebDriver driver) {

    try {//  w  w  w.  ja  v a 2s.c o m

        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.navigate().to("http://e1.dev.assetnation.com/all-equipment/equipmentone-listings");

        Thread.sleep(1000);
        driver.findElement(By.linkText("2")).click();//To go to 2nd page of the search results
        Thread.sleep(10000);

        //in search result there may be events, so finding first listing(excluding events) to offer exact bid

        List<WebElement> listings = driver.findElements(By.cssSelector("a[href*='/listing?listingid']"));
        int j = -1;
        for (int i = 1; i < listings.size(); i++) {
            j++;
            String s1 = listings.get(i).getAttribute("href");
            String s2[] = s1.split("/listing?");
            String s3[] = s2[1].split("&");
            String s4[] = s3[0].split("=");
            String id = s4[1];
            System.out.println("listing id is: " + id);
            System.out.println("listing-" + id);
            String listingText = driver.findElement(By.id("listing-" + id)).getText();
            //String Text[]=listingText.split("\n");
            System.out.println("text in listing is:................... " + listingText);
            if (listingText.contains("MAX BID")) {
                break;
            }

            i++;

        }

        System.out.println("number of listings in page: " + listings.size());

        //taking first listing (not concidering events)
        WebElement we = listings.get(j);
        String href = we.getAttribute("href");
        System.out.println("href of first listing is: " + href);
        // (//a[@href='http://e1.dev.assetnation.com/listing?listingid=316696&backToSearchButton=1']/following::*[@class='jsMinOfferjsAmountText'])[1]

        if (href.contains("http://e1.dev.assetnation.com"))
            href = href.replaceAll("http://e1.dev.assetnation.com", "");
        else if (href.contains("http://e1.dev.assetnation.com/"))
            href = href.replaceAll("http://e1.dev.assetnation.com/", "");

        String min_offer = driver
                .findElement(By
                        .xpath("(//a[@href='" + href + "']/following::*[@class='jsMinOffer jsAmountText'])[1]"))
                .getText();
        String min_offer2 = min_offer.substring(1, min_offer.length() - 3);
        String min_offer3 = min_offer2.replace(",", "");

        Integer minOffer = Integer.parseInt(min_offer3);
        System.out.println("minimum offer is: " + minOffer);
        Integer bidAmount = add + minOffer;
        String bidValue = String.valueOf(bidAmount);
        //clicking on Place a Bid button

        driver.findElement(
                By.xpath("(//a[@href='" + href + "']/following::*[@type='text' and @name='makeoffer'])[1]"))
                .clear();
        driver.findElement(
                By.xpath("(//a[@href='" + href + "']/following::*[@type='text' and @name='makeoffer'])[1]"))
                .sendKeys(bidValue);
        driver.findElement(By
                .xpath("(//a[@href='" + href + "']/following::*[@type='button' and @value='PLACE A BID'])[1]"))
                .click();
        Thread.sleep(2000);
        driver.findElement(By.xpath("(//a[@href='" + href
                + "']/following::*[@class='form-control jsOfferInput e1ConfirmInput' and@type='text'])[1]"))
                .sendKeys(bidValue);
        // String ss=driver.findElement(By.xpath("(//a[@href='"+href+"']/following::*[@class='form-control jsOfferInput'])[1]")).getText();

        driver.findElement(
                By.xpath("(//a[@href='" + href + "']/following::*[@type='button' and @value='CONTINUE'])[1]"))
                .click();
        Thread.sleep(2000);
        driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
        //some times we have confirmation check-box and some times we dont have
        try {
            driver.findElement(By.xpath("(//input[@class='jsTermsAgree' and @type='checkbox'])[2]")).click();
        } catch (Exception e) {
            System.out.println("there is no confirm check box");
        }
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.findElement(
                By.xpath("(//a[@href='" + href + "']/following::*[@type='submit' and @value='Submit'])[1]"))
                .click();
        Thread.sleep(2000);
        for (int i = 0; i < 20; i++) {
            if (driver
                    .findElement(
                            By.xpath("(//a[@href='" + href + "']/following::*[@class='jsMyMaxBidValue'])[1]"))
                    .getText().contains("$"))
                break;
            Thread.sleep(500);
        }
        String MyMaxBid = driver
                .findElement(By.xpath("(//a[@href='" + href + "']/following::*[@class='jsMyMaxBidValue'])[1]"))
                .getText();
        String MyMaxBid2 = MyMaxBid.replace(".00", ""); //$8,200.00
        String MyMaxBid3 = MyMaxBid2.replace("$", "").replace(",", "");

        System.out.println("bidded value is: " + bidValue);
        System.out.println("showing my bid value is: " + MyMaxBid3);
        if (MyMaxBid3.equals(bidValue))
            resultDetails.setFlag(true);
        else
            System.out.println("bid value is mis-matched");

    }

    catch (Exception e) {

        e.printStackTrace();
        resultDetails.setFlag(false);
    }

}

From source file:com.java.AppTestType_18_11_2015.java

public void EXACTOFFERINSEARCHRESULTSPAGE(WebDriver driver) {

    try {// w ww.j  a  v  a  2s.  co  m
        // suman 
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.navigate().to("http://e1.dev.assetnation.com/all-equipment/equipmentone-listings");

        Thread.sleep(1000);
        driver.findElement(By.linkText("2")).click();//To go to 2nd page of the search results
        Thread.sleep(10000);

        //in search result there may be events, so finding first listing(excluding events) to offer exact bid

        List<WebElement> listings = driver.findElements(By.cssSelector("a[href*='/listing?listingid']"));
        int j = -1;
        for (int i = 1; i < listings.size(); i++) {
            j++;
            String s1 = listings.get(i).getAttribute("href");
            String s2[] = s1.split("/listing?");
            String s3[] = s2[1].split("&");
            String s4[] = s3[0].split("=");
            String id = s4[1];
            System.out.println("listing id is: " + id);
            System.out.println("listing-" + id);
            String listingText = driver.findElement(By.id("listing-" + id)).getText();
            //String Text[]=listingText.split("\n");
            System.out.println("text in listing is:................... " + listingText);
            if (listingText.contains("MAX BID")) {
                break;
            }

            i++;

        }

        System.out.println("number of listings in page: " + listings.size());

        //taking first listing (not concidering events)
        WebElement we = listings.get(j);
        String href = we.getAttribute("href");
        System.out.println("href of first listing is: " + href);
        // (//a[@href='http://e1.dev.assetnation.com/listing?listingid=316696&backToSearchButton=1']/following::*[@class='jsMinOfferjsAmountText'])[1]

        if (href.contains("http://e1.dev.assetnation.com"))
            href = href.replaceAll("http://e1.dev.assetnation.com", "");
        else if (href.contains("http://e1.dev.assetnation.com/"))
            href = href.replaceAll("http://e1.dev.assetnation.com/", "");

        String min_offer = driver
                .findElement(By
                        .xpath("(//a[@href='" + href + "']/following::*[@class='jsMinOffer jsAmountText'])[1]"))
                .getText();
        String min_offer2 = min_offer.substring(1, min_offer.length() - 3);
        String min_offer3 = min_offer2.replace(",", "");

        Integer minOffer = Integer.parseInt(min_offer3);
        System.out.println("minimum offer is: " + minOffer);
        Integer bidAmount = add + minOffer;
        String bidValue = String.valueOf(bidAmount);
        //clicking on exact bid radio button
        driver.findElement(By.xpath(
                "(//a[@href='" + href + "']/following::*[@class='check-box' and @value='Exact Bid'])[1]"))
                .click();
        driver.findElement(
                By.xpath("(//a[@href='" + href + "']/following::*[@type='text' and @name='makeoffer'])[1]"))
                .clear();
        driver.findElement(
                By.xpath("(//a[@href='" + href + "']/following::*[@type='text' and @name='makeoffer'])[1]"))
                .sendKeys(bidValue);
        driver.findElement(By
                .xpath("(//a[@href='" + href + "']/following::*[@type='button' and @value='PLACE A BID'])[1]"))
                .click();
        Thread.sleep(2000);
        driver.findElement(By.xpath("(//a[@href='" + href
                + "']/following::*[@class='form-control jsOfferInput e1ConfirmInput' and@type='text'])[1]"))
                .sendKeys(bidValue);
        // String ss=driver.findElement(By.xpath("(//a[@href='"+href+"']/following::*[@class='form-control jsOfferInput'])[1]")).getText();

        driver.findElement(
                By.xpath("(//a[@href='" + href + "']/following::*[@type='button' and @value='CONTINUE'])[1]"))
                .click();
        Thread.sleep(2000);
        driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
        //some times we have confirmation check-box and some times we dont have
        try {
            driver.findElement(By.xpath("(//input[@class='jsTermsAgree' and @type='checkbox'])[2]")).click();
        } catch (Exception e) {
            System.out.println("there is no confirm check box");
        }
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.findElement(
                By.xpath("(//a[@href='" + href + "']/following::*[@type='submit' and @value='Submit'])[1]"))
                .click();
        Thread.sleep(2000);
        for (int i = 0; i < 20; i++) {
            if (driver
                    .findElement(
                            By.xpath("(//a[@href='" + href + "']/following::*[@class='jsMyMaxBidValue'])[1]"))
                    .getText().contains("$"))
                break;
            Thread.sleep(500);
        }
        String MyMaxBid = driver
                .findElement(By.xpath("(//a[@href='" + href + "']/following::*[@class='jsMyMaxBidValue'])[1]"))
                .getText();
        String MyMaxBid2 = MyMaxBid.replace(".00", ""); //$8,200.00
        String MyMaxBid3 = MyMaxBid2.replace("$", "").replace(",", "");

        System.out.println("bidded value is: " + bidValue);
        System.out.println("showing my bid value is: " + MyMaxBid3);
        if (MyMaxBid3.equals(bidValue))
            resultDetails.setFlag(true);
        else
            System.out.println("bid value is mis-matched");

    }

    catch (Exception e) {

        e.printStackTrace();
        resultDetails.setFlag(false);
    }

}