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


Java WebElement.clear方法代码示例

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


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

示例1: clear

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public void clear() throws Throwable {
    driver = new JavaDriver();
    WebElement textField = driver.findElement(By.cssSelector("text-field"));
    textField.clear();
    AssertJUnit.assertEquals("", textField.getText());
    textField.sendKeys("Lewis Carroll");
    AssertJUnit.assertEquals("Lewis Carroll", textField.getText());
    textField.clear();
    AssertJUnit.assertEquals("", textField.getText());
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:11,代码来源:JTextFieldTest.java

示例2: searchFor

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
/**
 * Types into the search bar in the top right and searches.
 * 
 * @param content
 *            - The value to type into the search bar.
 */
public void searchFor(String content) {
	this.focusForm(false);
	WebElement mGTypeArea = _wait.until(ExpectedConditions.presenceOfElementLocated(By.name("sysparm_search")));
	if (!mGTypeArea.getClass().toString().contains("focus")) {
		WebElement magnifyingGlass = _wait
				.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("[action='textsearch.do']")));
		magnifyingGlass.click();
	}
	if(!mGTypeArea.getAttribute("value").equalsIgnoreCase("")) {
		mGTypeArea.clear();
	}
	mGTypeArea.sendKeys(content);
	mGTypeArea.sendKeys(Keys.ENTER);
}
 
开发者ID:SeanABoyer,项目名称:ServiceNow_Selenium,代码行数:21,代码来源:ServiceNow.java

示例3: putText

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
@Override
public boolean putText(WebElement w, String... args) throws Exception{
	boolean result = false;
	String d = args[0];
	boolean includesReturn = false;
	if(d.indexOf("\\n") > -1 || d.indexOf("\\r") > -1){
		d = d.replace("\\n", "");
		d = d.replace("\\r", "");
		includesReturn = true;
	}
	try{
		w.clear();
		w.sendKeys(d);
		if(includesReturn){
			w.sendKeys(Keys.RETURN);
		}
		result = true;
	}catch(Exception e){
		e.printStackTrace();
		result = false;
	}
	Assert.assertTrue(result, w.toString() + " insert text " + d);
	return result;
}
 
开发者ID:saiscode,项目名称:kheera,代码行数:25,代码来源:AbstractPage.java

示例4: updateValue

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
/**
 * Update the specified element with the indicated value
 * 
 * @param element target element (input, select)
 * @param value desired value
 * @return 'true' if element value changed; otherwise 'false'
 */
public static boolean updateValue(WebElement element, String value) {
    Objects.requireNonNull(element, "[element] must be non-null");
    
    String tagName = element.getTagName().toLowerCase();
    if ("input".equals(tagName)) {
        if ("checkbox".equals(element.getAttribute("type"))) {
            return updateValue(element, Boolean.parseBoolean(value));
        } else if (!valueEquals(element, value)) {
            if (value == null) {
                element.clear();
            } else {
                WebDriverUtils.getExecutor(element).executeScript("arguments[0].select();", element);
                element.sendKeys(value);
            }
            return true;
        }
    } else if ("select".equals(tagName) && !valueEquals(element, value)) {
        new Select(element).selectByValue(value);
        return true;
    }
    return false;
}
 
开发者ID:Nordstrom,项目名称:Selenium-Foundation,代码行数:30,代码来源:ComponentContainer.java

示例5: enterIntoFieldInFieldset

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
/**
 * Enters the specified text into the field, within the specified fieldset.
 * @param text          The text to enter
 * @param fieldLabel    The field label
 * @param fieldsetLabel The fieldset label
 */
public void enterIntoFieldInFieldset(String text, String fieldLabel, String fieldsetLabel) {
    WebElement fieldsetElement;

    try {
        // find the fieldset with the fieldset label
        fieldsetElement = webDriver.findElement(
                By.xpath("//label[contains(text(),'" + fieldsetLabel + "')]/ancestor::fieldset[1]"));

    } catch (NoSuchElementException noSuchElement) {
        fieldsetElement = findFieldsetByLegend(fieldsetLabel);
    }

    // find the specified label (with the for="id" attribute)...
    WebElement labelElement = fieldsetElement.findElement(
            By.xpath(".//label[contains(text(),'" + fieldLabel + "')]"));

    // find the text element with id matching the for attribute
    // (search in the fieldset rather than the whole page, to get around faulty HTML where id's aren't unique!)
    WebElement textElement = fieldsetElement.findElement(By.id(labelElement.getAttribute("for")));
    textElement.clear();
    textElement.sendKeys(text);
}
 
开发者ID:dvsa,项目名称:mot-automated-testsuite,代码行数:29,代码来源:WebDriverWrapper.java

示例6: login

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public void login() throws Throwable {
    driver = new JavaDriver();
    WebElement passField = driver.findElement(By.cssSelector("password-field"));
    AssertJUnit.assertEquals("true", passField.getAttribute("enabled"));
    passField.clear();
    AssertJUnit.assertEquals("", passField.getText());
    passField.sendKeys("password");
    WebElement button = driver.findElement(By.cssSelector("button"));
    button.click();
    driver.switchTo().window("Error Message");
    WebElement label = driver.findElement(By.cssSelector("label[text*='Invalid']"));
    AssertJUnit.assertEquals("Invalid password. Try again.", label.getText());
    WebElement button1 = driver.findElement(By.cssSelector("button"));
    button1.click();
    driver.switchTo().window("JPasswordFieldTest");
    passField.clear();
    passField.sendKeys("bugaboo", Keys.ENTER);
    driver.switchTo().window("Message");
    WebElement label2 = driver.findElement(By.cssSelector("label[text*='Success']"));
    AssertJUnit.assertEquals("Success! You typed the right password.", label2.getText());
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:22,代码来源:JPasswordFieldTest.java

示例7: updateText

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
/**
 * Update a html input text with a text.
 *
 * @param pageElement
 *            Is target element
 * @param textOrKey
 *            Is the new data (text or text in context (after a save))
 * @param keysToSend
 *            character to send to the element after {@link org.openqa.selenium.WebElement#sendKeys(CharSequence...) sendKeys} with textOrKey
 * @param args
 *            list of arguments to format the found selector with
 * @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_ERROR_ON_INPUT} message (with screenshot, no exception)
 * @throws FailureException
 *             if the scenario encounters a functional error
 */
protected void updateText(PageElement pageElement, String textOrKey, CharSequence keysToSend, Object... args) throws TechnicalException, FailureException {
    String value = Context.getValue(textOrKey) != null ? Context.getValue(textOrKey) : textOrKey;
    if (!"".equals(value)) {
        try {
            WebElement element = Context.waitUntil(ExpectedConditions.elementToBeClickable(Utilities.getLocator(pageElement, args)));
            element.clear();
            if (DriverFactory.IE.equals(Context.getBrowser())) {
                String javascript = "arguments[0].value='" + value + "';";
                ((JavascriptExecutor) getDriver()).executeScript(javascript, element);
            } else {
                element.sendKeys(value);
            }
            if (keysToSend != null) {
                element.sendKeys(keysToSend);
            }
        } catch (Exception e) {
            new Result.Failure<>(e.getMessage(), Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_ERROR_ON_INPUT), pageElement, pageElement.getPage().getApplication()), true,
                    pageElement.getPage().getCallBack());
        }
    } else {
        logger.debug("Empty data provided. No need to update text. If you want clear data, you need use: \"I clear text in ...\"");
    }
}
 
开发者ID:NoraUi,项目名称:NoraUi,代码行数:41,代码来源:Step.java

示例8: changeData

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public void changeData(String value){

        WebElement text = getDriver().findElement(By.id("form:text"));
        WebElement button = getDriver().findElement(By.id("form:modify"));

        text.clear();
        text.sendKeys(value);
        button.click();
        waitForPageToLoad();
    }
 
开发者ID:arcuri82,项目名称:testing_security_development_enterprise_systems,代码行数:11,代码来源:HomePageObject.java

示例9: sendText

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public void sendText(By inputBy, String text){
	logger.log("Clear + Send text \"" + text + "\" to " + inputBy );
	WebElement input = findElement(inputBy);
	
	for (int i=1; i<=3; i++){
		input.clear();
		ThreadUtils.sleepQuiet(500);
		if(input.getText().isEmpty()){
			break;
		}
	}
			
	input.sendKeys(text);
	ThreadUtils.sleepQuiet(500);		
}
 
开发者ID:danrusu,项目名称:mobileAutomation,代码行数:16,代码来源:Page.java

示例10: clearText

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
@Override
public boolean clearText(WebElement w) throws Exception{
	boolean result = false;
	try{
		w.clear();
		result = true;
	} catch(Exception e){
		e.printStackTrace();
		result = false;
	}
	Assert.assertTrue(result, "Clear " + w.toString());
	return result;
}
 
开发者ID:saiscode,项目名称:kheera,代码行数:14,代码来源:AbstractPage.java

示例11: enterIntoFieldWithLabel

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
/**
 * Enters the specified text into the field.
 * @param text  The text to enter
 */
public void enterIntoFieldWithLabel(String labelText, String text) {
    // find the input associated with the specified label...
    WebElement labelElement = webDriver.findElement(
            By.xpath("//*[text() = '" + labelText + "']//ancestor::label"));
    WebElement textElement = webDriver.findElement(By.id(labelElement.getAttribute("for")));
    textElement.clear();
    textElement.sendKeys(text);
}
 
开发者ID:dvsa,项目名称:mot-automated-testsuite,代码行数:13,代码来源:WebDriverWrapper.java

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

示例13: enterIntoField

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
/**
 * Enters the specified text into the field.
 * @param text  The text to enter
 * @param label The field label
 */
public void enterIntoField(String text, String label) {
    // find the input associated with the specified label...
    WebElement labelElement = webDriver.findElement(By.xpath("//label[contains(text(),'" + label + "')]"));
    WebElement textElement = webDriver.findElement(By.id(labelElement.getAttribute("for")));
    textElement.clear();
    textElement.sendKeys(text);
}
 
开发者ID:dvsa,项目名称:mot-automated-testsuite,代码行数:13,代码来源:WebDriverWrapper.java

示例14: run

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

    By locator = this.readLocatorArgument("locator");
    String text = this.readStringArgument("text", null);
    String key = this.readStringArgument("key", null);
    Boolean clearContent = this.readBooleanArgument("clearContent", Boolean.FALSE);
    Boolean sendEnter = this.readBooleanArgument("sendEnter", Boolean.FALSE);

    this.waitForAsyncCallsToFinish();

    try {
        WebElement element = this.getElement(locator);
        WebDriverWait wait = new WebDriverWait(this.driver, this.explicitWaitSec);
        wait.until(ExpectedConditions.elementToBeClickable(element));

        if (clearContent) {
            element.clear();
        }

        if (text != null) {
            element.sendKeys(text);
        } else if (key != null) {
            element.sendKeys(Keys.valueOf(key.toUpperCase()));
        } else {
            throw new RuntimeException("Neither the \"text\" argument, nor the \"key\" argument were provided.");
        }

        if (sendEnter) {
            element.sendKeys(Keys.ENTER);
        }
    } catch (Exception ex) {
        throw new RuntimeException(String.format(
                "Failed sending keys to element %s",
                locator), ex
        );
    }
}
 
开发者ID:mcdcorp,项目名称:opentest,代码行数:40,代码来源:SendKeys.java

示例15: getText

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public void getText() throws Throwable {
    driver = new JavaDriver();
    WebElement passField = driver.findElement(By.cssSelector("password-field"));
    AssertJUnit.assertEquals("true", passField.getAttribute("enabled"));
    passField.clear();
    AssertJUnit.assertEquals("", passField.getText());
    passField.sendKeys("password");
    AssertJUnit.assertEquals("password", passField.getText());
    passField.clear();
    AssertJUnit.assertEquals("", passField.getText());
    passField.sendKeys("[email protected]");
    AssertJUnit.assertEquals("[email protected]", passField.getText());
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:14,代码来源:JPasswordFieldTest.java


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