当前位置: 首页>>代码示例>>Java>>正文


Java WebElement.getAttribute方法代码示例

本文整理汇总了Java中org.openqa.selenium.WebElement.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java WebElement.getAttribute方法的具体用法?Java WebElement.getAttribute怎么用?Java WebElement.getAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openqa.selenium.WebElement的用法示例。


在下文中一共展示了WebElement.getAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: map

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
/**
 * 1. map elements of interest to their name
 * 2. reload elements from the page every time `map` is called  
 * 
 * E.g., Say ELEMENT_LOCATORS=id 
 * 			and <input id="username" type="text"></input>
 * 			then nameElementMap will contain "username" => WebElement
 */
@Override
protected void map(AbstractPage p) {
	getBys();
	List<WebElement> elements = new ArrayList<WebElement>();
	for (By by : bys) {
		elements.addAll(driver.findElements(by));
	}
	PageFactory.initElements(driver, this);
	String[] tokens = locators.split(",");
	for(WebElement w: elements) {
		for (String s : tokens) {
			try{
				String attr = w.getAttribute(s);//throws StaleElementReferenceException
				if (attr != null) {
					nameElementMap.put(attr, w);
				}
			}catch(StaleElementReferenceException se){
				//ignoring elements which have become stale because
				//a stale object shouldn't have to be referenced 
				//by an automation script
			}
		}
	}
}
 
开发者ID:saiscode,项目名称:kheera,代码行数:33,代码来源:PageObject.java

示例2: run

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
@Override
public void run() {

    super.run();

    By locator = this.readLocatorArgument("locator");

    this.waitForAsyncCallsToFinish();

    WebElement element = this.getElement(locator);
    String readonly = element.getAttribute("readonly");
    if (readonly == null) {
        throw new RuntimeException(String.format(
                "Assertion failed: the \"readonly\" attribute was not set on element %s",
                locator));
    }
}
 
开发者ID:mcdcorp,项目名称:opentest,代码行数:18,代码来源:AssertElementReadOnly.java

示例3: run

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
@Override
public void run() {

    super.run();

    By locator = this.readLocatorArgument("locator");

    this.waitForAsyncCallsToFinish();

    WebElement element = this.getElement(locator);
    String readonly = element.getAttribute("readonly");
    if (readonly != null) {
        throw new RuntimeException(String.format(
                "Assertion failed: the \"readonly\" attribute was set on element %s",
                locator));
    }
}
 
开发者ID:mcdcorp,项目名称:opentest,代码行数:18,代码来源:AssertElementNotReadOnly.java

示例4: columnSelection

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public void columnSelection() throws Throwable {
    driver = new JavaDriver();
    List<WebElement> checkboxes = driver.findElements(By.cssSelector("check-box"));

    // Setting Column Selection
    checkboxes.get(1).click();
    List<WebElement> radiobuttons = driver.findElements(By.cssSelector("radio-button"));

    // Setting Single Selection
    radiobuttons.get(1).click();

    WebElement table = driver.findElement(By.cssSelector("table"));
    int columnCount = new Integer(table.getAttribute("columnCount"));
    AssertJUnit.assertEquals(5, columnCount);
    for (int colNum = 0; colNum < columnCount; colNum++) {
        assertClickOnColumn(table, colNum);
    }

    assertShiftClickSingleSelection(table);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:21,代码来源:JTableColumnSelectionTest.java

示例5: colSelectionSingleInterval

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public void colSelectionSingleInterval() throws Throwable {
    driver = new JavaDriver();
    List<WebElement> checkboxes = driver.findElements(By.cssSelector("check-box"));

    // Setting Column Selection
    checkboxes.get(1).click();
    List<WebElement> radiobuttons = driver.findElements(By.cssSelector("radio-button"));

    // Setting Single Interval Selection
    radiobuttons.get(2).click();

    WebElement table = driver.findElement(By.cssSelector("table"));
    int colCount = new Integer(table.getAttribute("columnCount"));
    AssertJUnit.assertEquals(5, colCount);
    for (int colNum = 0; colNum < colCount; colNum++) {
        assertClickOnColumn(table, colNum);
    }

    assertShiftClickSingleIntSelection(table, 1, 3, "1, 2, 3");
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:21,代码来源:JTableColumnSelectionTest.java

示例6: etrePlein

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
@Override
public void etrePlein(String type, String selector) {
    this.logger.info("etrePlein(String id)");
    By locator = BySelec.get(type, selector);
    WebElement elem = wait.until(ExpectedConditions.presenceOfElementLocated(locator));

    if (elem.getAttribute("value") != null) {
        if (elem.getAttribute("value").toString().trim().isEmpty()) {
            Assert.fail("l'élément ne devrait pas être vide!");
        }
    } else {
        if (elem.getText().trim().isEmpty()) {
            Assert.fail("l'élément ne devrait pas être vide!");
        }
    }
}
 
开发者ID:Nonorc,项目名称:saladium,代码行数:17,代码来源:SaladiumDriver.java

示例7: getText

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
@Override
public String getText(WebElement w) {
	String returnValue = "";
	try {
		if (null != w.getAttribute("value")) {
			returnValue += w.getAttribute("value");
		} else if (null != w.getText()) {
			returnValue += w.getText();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return returnValue;
}
 
开发者ID:saiscode,项目名称:kheera,代码行数:15,代码来源:AbstractPage.java

示例8: getElementText

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
private String getElementText(WebElement element) {
    if (element.getTagName().equals("input")) {
        return element.getAttribute("value");
    }

    return element.getText();
}
 
开发者ID:NHS-digital-website,项目名称:hippo,代码行数:8,代码来源:SiteSteps.java

示例9: download

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
@Then("I can download(?: following files)?:")
public void iCanDownload(final DataTable downloadTitles) throws Throwable {
    for (List<String> downloadLink : downloadTitles.asLists(String.class)) {
        String linkText = downloadLink.get(0);
        String linkFileName = downloadLink.get(1);

        WebElement downloadElement = sitePage.findElementWithTitle(linkText);

        assertThat("I can find download link with title: " + linkText,
            downloadElement, is(notNullValue()));

        String url = downloadElement.getAttribute("href");
        assertEquals("I can find link with expected URL for file " + linkFileName, URL + urlLookup.lookupUrl(linkFileName), url);

        if (acceptanceTestProperties.isHeadlessMode()) {
            // At the moment of writing, there doesn't seem to be any easy way available to force Chromedriver
            // to download files when operating in headless mode. It appears that some functionality has been
            // added to DevTools but it's not obvious how to trigger that from Java so, for now at least,
            // we'll only be testing file download when operating in a full, graphical mode.
            //
            // See bug report at https://bugs.chromium.org/p/chromium/issues/detail?id=696481 and other reports
            // available online.
            log.warn("Not testing file download due to running in a headless mode, will just check link is present.");
        } else {
            // Trigger file download by click the <a> tag.
            sitePage.clickOnElement(downloadElement);

            final Path downloadedFilePath = Paths.get(acceptanceTestProperties.getDownloadDir().toString(),
                linkFileName);

            waitUntilFileAppears(downloadedFilePath);
        }
    }
}
 
开发者ID:NHS-digital-website,项目名称:hippo,代码行数:35,代码来源:SiteSteps.java

示例10: highlightElement

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
private void highlightElement(
                               boolean disregardConfiguration ) {

    if (webDriver instanceof PhantomJSDriver) {
        // it is headless browser
        return;
    }

    if (disregardConfiguration || UiEngineConfigurator.getInstance().getHighlightElements()) {

        try {
            WebElement webElement = RealHtmlElementLocator.findElement(element);
            String styleAttrValue = webElement.getAttribute("style");

            JavascriptExecutor js = (JavascriptExecutor) webDriver;
            js.executeScript("arguments[0].setAttribute('style', arguments[1]);",
                             webElement,
                             "background-color: #ff9; border: 1px solid yellow; box-shadow: 0px 0px 10px #fa0;"); // to change text use: "color: yellow; text-shadow: 0 0 2px #f00;"
            Thread.sleep(500);
            js.executeScript("arguments[0].setAttribute('style', arguments[1]);",
                             webElement,
                             styleAttrValue);
        } catch (Exception e) {
            // swallow this error as highlighting is not critical
        }
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:28,代码来源:RealHtmlElementState.java

示例11: rowSelectionSingleInterval

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public void rowSelectionSingleInterval() throws Throwable {
    driver = new JavaDriver();
    List<WebElement> radiobuttons = driver.findElements(By.cssSelector("radio-button"));

    // Setting Single Interval Selection
    radiobuttons.get(2).click();
    WebElement table = driver.findElement(By.cssSelector("table"));
    int rowCount = new Integer(table.getAttribute("rowCount"));
    AssertJUnit.assertEquals(5, rowCount);
    for (int rowNum = 0; rowNum < rowCount; rowNum++) {
        assertClickOnRow(table, rowNum);
    }

    assertShiftClickSingleIntSelection(table, 1, 3, "1, 2, 3");
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:16,代码来源:JTableRowSelectionTest.java

示例12: setFileInputValue

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
/**
*
* @param webDriver {@link WebDriver} instance
* @param value the file input value to set
*/
protected void setFileInputValue( WebDriver webDriver, String value ) {

    String locator = this.getElementProperties()
                         .getInternalProperty(HtmlElementLocatorBuilder.PROPERTY_ELEMENT_LOCATOR);

    String css = this.getElementProperty("_css");

    WebElement element = null;

    if (!StringUtils.isNullOrEmpty(css)) {
        element = webDriver.findElement(By.cssSelector(css));
    } else {
        element = webDriver.findElement(By.xpath(locator));
    }

    try {
        element.sendKeys(value);
    } catch (ElementNotVisibleException enve) {

        if (!UiEngineConfigurator.getInstance().isWorkWithInvisibleElements()) {
            throw enve;
        }
        // try to make the element visible overriding some CSS properties
        // but keep in mind that it can be still invisible using another CSS and/or JavaScript techniques
        String styleAttrValue = element.getAttribute("style");
        JavascriptExecutor jsExec = (JavascriptExecutor) webDriver;
        try {
            jsExec.executeScript("arguments[0].setAttribute('style', arguments[1]);",
                                 element,
                                 "display:'block'; visibility:'visible'; top:'auto'; left:'auto'; z-index:999;"
                                          + "height:'auto'; width:'auto';");
            element.sendKeys(value);
        } finally {
            jsExec.executeScript("arguments[0].setAttribute('style', arguments[1]);", element,
                                 styleAttrValue);
        }

    } catch (InvalidElementStateException e) {
        throw new SeleniumOperationException(e.getMessage(), e);
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:47,代码来源:HtmlFileBrowse.java

示例13: isDisabledElement

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public static boolean isDisabledElement(WebElement element){
    return element.getAttribute("disabled") != null && element.getAttribute("disabled").equals("true");
}
 
开发者ID:WileyLabs,项目名称:teasy,代码行数:4,代码来源:IETestUtils.java

示例14: fillValue

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
/**
 * 填入值,如果目标元素有readonly,则不做任何操作
 * @param ele 目标元素
 * @param value 要填入的值,null会当作空字符串
 * @param append 是否追加
 */
private void fillValue(Element ele, Object value, boolean append)
{
	if(value == null)
	{
		value = "";
	}

	WebElement webEle = searchStrategyUtils.findStrategy(WebElement.class, ele).search(ele);
	if(webEle != null)
	{
		String readonlyAttr = webEle.getAttribute("readonly");
		if(StringUtil.isNotBlank(readonlyAttr))
		{
			logger.warn("{} is readonly, will do not call method setValue.", webEle.toString());
			return;
		}
		
		String valueStr = value.toString();
		try
		{
			fill(webEle, valueStr, append);
		}
		catch(WebDriverException e)
		{
			if(e.getMessage().contains("is not clickable at point"))
			{
				((JavascriptExecutor) engine.getDriver()).executeScript("arguments[0].scrollIntoView();", webEle);

				fill(webEle, valueStr, append);
			}
			else
			{
				e.printStackTrace();
			}
		}
	}
	else
	{
		logger.error(String.format("can not found element [%s].", ele));
	}
}
 
开发者ID:LinuxSuRen,项目名称:phoenix.webui.framework,代码行数:48,代码来源:SeleniumValueEditor.java

示例15: cadastro

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
@Test
    public void cadastro() throws InterruptedException {

        WebDriverWait wait = new WebDriverWait(driver, 30);

        wait.until(ExpectedConditions.presenceOfElementLocated(By.id("Name")));
        WebElement name = driver.findElement(By.id("Name"));
        name.sendKeys("Vitor Cardoso");

        wait.until(ExpectedConditions.presenceOfElementLocated(By.id("Email")));
        WebElement email = driver.findElement(By.id("Email"));
        email.sendKeys(("[email protected]"));

        wait.until(ExpectedConditions.presenceOfElementLocated(By.id("Site")));
        WebElement site = driver.findElement(By.id("Site"));
        site.sendKeys("www.doqconsulting.com.br");

        wait.until(ExpectedConditions.presenceOfElementLocated(By.id("Subject")));
        WebElement assunto = driver.findElement(By.id("Subject"));
        assunto.sendKeys("Teste Selenium com assert");

        wait.until(ExpectedConditions.presenceOfElementLocated(By.id("Message")));
        WebElement message = driver.findElement(By.id("Message"));
        message.sendKeys
                ("Gostaria de saber mais sobre a DOQ Consulting e como podemos ajudá-lo? Envie sua mensagem pelo site ou em nossas redes sociais.");

        // SUBMIT AND ASSERT
        name.submit();
        String respname = name.getAttribute("value");
        Assert.assertEquals(respname,"Vitor Cardoso");

        email.submit();
        String resp = email.getAttribute("value");
        Assert.assertEquals(resp,"[email protected]");

        site.submit();
        String respsite = site.getAttribute("value");
        Assert.assertEquals(respsite,"www.doqconsulting.com.br");

        assunto.submit();
        String respassunto = assunto.getAttribute("value");
        Assert.assertEquals(respassunto,"Teste Selenium com assert");

        message.submit();
        String respmsg = message.getAttribute("value");
        Assert.assertEquals(respmsg,
                "Gostaria de saber mais sobre a DOQ Consulting e como podemos ajudá-lo? Envie sua mensagem pelo site ou em nossas redes sociais.");

        wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("button[class='btn btn-send']")));
        WebElement sendclick = driver.findElement(By.cssSelector("button[class='btn btn-send']"));
        sendclick.click(); /*Código comentado devido ao erro do webdriver com o firefox*/

//        wait.until(ExpectedConditions.presenceOfElementLocated(By.className("col-sm-7 col-sm-offset-1")));
//        WebElement validatemsg = driver.findElement(By.className("col-sm-7 col-sm-offset-1"));
//        String test = validatemsg.getText();
//        Assert.assertEquals(test," *Sua mensagem foi enviada com sucesso, logo mais um de nosso consultores irão avaliar o seu caso e entrar em contato. ");


    }
 
开发者ID:vitorc,项目名称:QA_Begin,代码行数:60,代码来源:TestContactDoq.java


注:本文中的org.openqa.selenium.WebElement.getAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。