Clear text box content by using actions class sendkeys method in selenium webdriver.
Like our facebook page www.facebook.com/ankprotraining
Clear text box content by using actions class sendkeys sendkeys method in selenium webdriver.
Actions class SendKeys method :
SendKeys(string keysToSend)- Sends a sequence of keystrokes to the browser.
SendKeys(IWebElement element, string keysToSend)- Sends a sequence of keystrokes to the specified element in the browser.
Actions class KeyDown method :
KeyDown(string theKey)- Sends a modifier key down message to the browser.
KeyDown(IWebElement element, string theKey)-
Sends a modifier key down message to the specified element in the browser.
Actions class KeyUp method :
KeyUp(string theKey) -Sends a modifier key up message to the browser.
KeyUp(IWebElement element, string theKey)- Sends a modifier up down message to the specified element in the browser.
Possible Interview Questions on actions class sendkeys, keyup and keydown methods.
Code :
[TestMethod]
public void ClearTextWithoutUsingSendKeys()
{
IWebDriver driver = new FirefoxDriver();
driver.Url = "http://ankpro.com/Account/Register";
Actions actions = new Actions(driver);
driver.FindElement(By.Id("Email")).SendKeys("[email protected]");
Thread.Sleep(2000);
actions
.Click(driver.FindElement(By.Id("Email")))
.SendKeys(Keys.Control + "a" + Keys.Backspace)
.Build()
.Perform();
Thread.Sleep(2000);
driver.Quit();
}