I am using HtmlUnitDriver & FirefoxDriver.Here is my code:
HtmlUnitDriver webDriver = new HtmlUnitDriver(false);
I have entered username & password using code below:
WebElement webElement = webDriver.findElement(By.xpath("some xpath here"));
webElement.sendKeys("some value here");
It works fine,it takes username & password successfully.Now I want to submit this after pressing ENTER key.So please guide me how to press ENTER key using HtmlUnitDriver object.
You need to first select an element (input, textfield ...) using findElement
. This will return a WebElement
.
On this object you can use the method sendKeys(java.lang.CharSequence... keysToSend)
.
From the API : http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebElement.html
sendKeys(java.lang.CharSequence... keysToSend)
Use this method to simulate typing into an element, which may set its value.
You can use http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/Keys.html#ENTER
WebDriver driver = new HtmlUnitDriver(false);
WebElement pw = driver.findElement(By.id("XX"));
pw.sendKeys(YY);
pw.sendKeys(Keys.ENTER);
driver.switchTo().activeElement().sendKeys(Keys.ENTER);
That will send to the current active element. Use the findElement
functions to specify a particular element to interact with.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.