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


Java WebElement.getText方法代码示例

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


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

示例1: getValue

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
/**
 * @return the single selection value
 */
@Override
@PublicAtsApi
public String getValue() {

    new HiddenHtmlElementState(this).waitToBecomeExisting();

    HtmlUnitWebElement selectElement = HiddenHtmlElementLocator.findElement(this);
    List<WebElement> optionElements = selectElement.findElements(By.tagName("option"));
    for (WebElement element : optionElements) {
        if (element.isSelected()) {
            return element.getText();
        }
    }
    throw new SeleniumOperationException("There is no selected 'option' in " + this.toString());
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:19,代码来源:HiddenHtmlSingleSelectList.java

示例2: checkDoubleClickEvent

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
private void checkDoubleClickEvent(int eventToCheck) throws InterruptedException, InvocationTargetException, AWTException {
    events = eventToCheck;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    Thread.sleep(50);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().contains("(2");
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(button, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    new Actions(driver).moveToElement(b).doubleClick().perform();
    AssertJUnit.assertEquals(expected, t.getText());
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:39,代码来源:NativeEventsTest.java

示例3: enteredGeneratesSameEvents

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public void enteredGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_ENTERED;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.keyPress(KeyEvent.VK_ALT);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    r.keyRelease(KeyEvent.VK_ALT);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    new Actions(driver).moveToElement(t).keyDown(Keys.ALT).moveToElement(b).click().keyUp(Keys.ALT).perform();
    AssertJUnit.assertEquals(expected, t.getText());

}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:39,代码来源:NativeEventsTest.java

示例4: getValues

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
/**
 * @return the selected values
 */
@Override
@PublicAtsApi
public String[] getValues() {

    new RealHtmlElementState(this).waitToBecomeExisting();

    WebElement element = RealHtmlElementLocator.findElement(this);
    Select select = new Select(element);
    List<WebElement> selectedOptions = select.getAllSelectedOptions();
    String[] result = new String[selectedOptions.size()];
    int i = 0;
    for (WebElement selectedOption : selectedOptions) {
        result[i++] = selectedOption.getText();
    }
    return result;
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:20,代码来源:RealHtmlMultiSelectList.java

示例5: checkText

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
/**
 * Checks if HTML text contains expected value.
 *
 * @param pageElement
 *            Is target element
 * @param textOrKey
 *            Is the new data (text or text in context (after a save))
 * @throws TechnicalException
 *             is thrown if you have a technical error (format, configuration, datas, ...) in NoraUi.
 *             Exception with {@value com.github.noraui.utils.Messages#FAIL_MESSAGE_WRONG_EXPECTED_VALUE} message (with screenshot, with exception) or with
 *             {@value com.github.noraui.utils.Messages#FAIL_MESSAGE_UNABLE_TO_FIND_ELEMENT} message
 *             (with screenshot, with exception)
 * @throws FailureException
 *             if the scenario encounters a functional error
 */
protected void checkText(PageElement pageElement, String textOrKey) throws TechnicalException, FailureException {
    WebElement webElement = null;
    String value = Context.getValue(textOrKey) != null ? Context.getValue(textOrKey) : textOrKey;
    try {
        webElement = Context.waitUntil(ExpectedConditions.presenceOfElementLocated(Utilities.getLocator(pageElement)));
    } catch (Exception e) {
        new Result.Failure<>(e.getMessage(), Messages.getMessage(Messages.FAIL_MESSAGE_UNABLE_TO_FIND_ELEMENT), true, pageElement.getPage().getCallBack());
    }

    String innerText = webElement == null ? null : webElement.getText();
    logger.info("checkText() expected [{}] and found [{}].", value, innerText);
    if (!value.equals(innerText)) {
        new Result.Failure<>(innerText, Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_WRONG_EXPECTED_VALUE), pageElement, value, pageElement.getPage().getApplication()), true,
                pageElement.getPage().getCallBack());
    }
}
 
开发者ID:NoraUi,项目名称:NoraUi,代码行数:32,代码来源:Step.java

示例6: stepCheckValue

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
@Step
@Then("значение элемента \"$fieldName\" равно \"$expectedValueOrKeyword\"")
public void stepCheckValue(String fieldName, String expectedValueOrKeyword) {
    WebElement webElement = getWebElementByName(fieldName);
    String actualElement = webElement.getText();
    String expectedValue = propertyUtils.injectProperties(expectedValueOrKeyword);
    assertEquals(format("Значение поля [%s] не соответствует ожидаемому [%s]", actualElement, expectedValue), expectedValue, actualElement);
}
 
开发者ID:alfa-laboratory,项目名称:colibri-ui,代码行数:9,代码来源:CheckSteps.java

示例7: setValue

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
@Override
public void setValue(Element ele, Object value)
{
    ElementsSearchStrategy<WebElement> strategy = searchStrategyUtils.findElementsStrategy(WebElement.class, ele);
    
    List<WebElement> eleList = strategy.searchAll(ele);
    
    for(int i = 0; i < eleList.size(); i++)
    {
        WebElement webEle = eleList.get(i);
        String tagName = webEle.getTagName();
        String text = webEle.getText();
        
        String attrName = null;
        String attrValue = null;
        
        if(!webEle.isDisplayed())
        {
            continue;
        }
        
        if(filter.filter(tagName, attrName, attrValue, text))
        {
            webEle.sendKeys(value.toString());
        }
    }
}
 
开发者ID:LinuxSuRen,项目名称:phoenix.webui.framework,代码行数:28,代码来源:SeleniumMultiValueEditor.java

示例8: 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

示例9: getAttributes

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
void getAttributes() throws Throwable {
    driver = new JavaDriver();
    WebElement textArea = driver.findElement(By.cssSelector("text-area"));
    AssertJUnit.assertEquals("true", textArea.getAttribute("editable"));
    textArea.sendKeys("Systems", Keys.SPACE);
    String previousText = textArea.getText();
    textArea.clear();
    textArea.sendKeys("Jalian" + previousText);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:10,代码来源:JTextAreaTest.java

示例10: getCounterValue

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public Integer getCounterValue(){
    WebElement text = getDriver().findElement(By.id("form:counterTextId"));
    String value = text.getText();
    try{
        return Integer.parseInt(value);
    } catch (Exception e) {
        return null;
    }
}
 
开发者ID:arcuri82,项目名称:testing_security_development_enterprise_systems,代码行数:10,代码来源:CounterPageObject.java

示例11: rightClickGeneratesSameEvents

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public void rightClickGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_CLICKED;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON3_MASK);
    r.mouseRelease(InputEvent.BUTTON3_MASK);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    new Actions(driver).moveToElement(b).contextClick().perform();
    AssertJUnit.assertEquals(expected, t.getText());

}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:37,代码来源:NativeEventsTest.java

示例12: 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

示例13: getOppositeUser

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
private static String getOppositeUser(String transactionNo) {
	// ��ȡ�ؼ��ֶ�Ӧ��������
	WebElement keywordInput = driver.findElement(By.id("J-keyword"));
	keywordInput.clear();
	keywordInput.sendKeys(transactionNo);
	WebElement keywordSelect = driver.findElement(By.id("keyword"));
	List<WebElement> options = keywordSelect.findElements(By.tagName("option"));
	// until������ʾֱ���ɵ��ٵ�
	// WebElement selectElement = wait.until(ExpectedConditions
	// .visibilityOfElementLocated(By.id("keyword")));
	// ��Ҫִ��JavaScript��䣬����ǿתdriver
	JavascriptExecutor js = (JavascriptExecutor) driver;
	// Ҳ������ô��setAttribute("style","");
	js.executeScript("document.getElementById('keyword').style.display='list-item';");
	js.executeScript("document.getElementById('keyword').removeAttribute('smartracker');");
	js.executeScript("document.getElementById('keyword').options[1].selected = true;");
	js.executeScript("document.getElementById('J-select-range').style.display='list-item';");
	// ���ý���ʱ��ѡ��
	Select selectTime = new Select(driver.findElement(By.id("J-select-range")));
	selectTime.selectByIndex(3);// ѡ�е������������
	System.out.println("selectTime.isMultiple() : " + selectTime.isMultiple());
	// ���ùؼ���ѡ��
	Select selectKeyword = new Select(driver.findElement(By.id("keyword")));
	// selectKeyword.selectByValue("bizInNo");//�˴���value��д<option>��ǩ�е�valueֵ
	selectKeyword.selectByIndex(1);// ѡ�е��ǽ��׺�
	System.out.println("selectKeyword.isMultiple() : " + selectKeyword.isMultiple());
	WebElement queryButton = driver.findElement(By.id("J-set-query-form"));// �õ�������ť
	// ���������ť
	queryButton.submit();
	WebElement tr = driver.findElement(By.id("J-item-1"));// �Ȼ�ȡtr
	WebElement td = tr.findElement(By.xpath("//*[@id=\"J-item-1\"]/td[5]/p[1]"));
	return td.getText();
}
 
开发者ID:qwl-nju,项目名称:AlipayAuto,代码行数:34,代码来源:AlipayAuto.java

示例14: all

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public Units2 all() {
    if (unit2Cache != null) {
        return new Units2(unit2Cache);
    }

    unit2Cache = new Units2();
    List<WebElement> elements = driver.findElements(By.cssSelector("span.unit2"));
    for (WebElement element : elements) {
        String name = element.getText();
        int id = Integer.parseInt(element.findElement(By.tagName("input")).getAttribute("value"));
        unit2Cache.add(new Unit2Data().withId(id).withTextField(name));
    }

    return new Units2(unit2Cache);
}
 
开发者ID:SpaceHead1C,项目名称:module-template,代码行数:16,代码来源:Unit2Helper.java

示例15: stepCheckValueInDynamicFields

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
@Step
@Then("значение динамического поля \"$field\" равно \"$expectedValue\"")
public void stepCheckValueInDynamicFields(@Named("$field") String field, @Named("$expectedValue") String expectedValue) {
    IElement parent = getCurrentPage().getElementByName(field);
    IElement nested = pageProvider.getPageByName(DYNAMIC_FIELDS_PAGE_NAME).getElementByName(EDIT_TEXT_NAME);
    WebElement elementFound = finder.findNestedWebElement(parent, nested);
    String actualElement = elementFound.getText();
    assertEquals(format("Значение поля [%s] не соответствует ожидаемому [%s]", actualElement, expectedValue), expectedValue, actualElement);
}
 
开发者ID:alfa-laboratory,项目名称:colibri-ui-template,代码行数:10,代码来源:AndroidDynamicFieldSteps.java


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