2

I am new to C# & not able to delete some textbox content using Selenium Clear command. In such situation I was trying the below command when I was working in Java.

webelement.sendKeys(Keys.chord(Keys.CONTROL,"a", Keys.DELETE)); 

Now in C#, the chord command is not available.

I have gone through the Keys class please find the link https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/Keys.html and believe chord is not there for C#. Do we have any alternative to perform the same operation. I am able to delete the inputs from textbox using JavaScript but how can I achieve pressing many keys at once in C#.

Currently using this approach using JavaScript

    public static void clearTextboxContentUsingJS(IWebDriver driver, IWebElement element)
    {
        ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].value ='';", element);
    }
braX
  • 11,506
  • 5
  • 20
  • 33
Ashutosh
  • 35
  • 5
  • https://stackoverflow.com/questions/35127108/how-to-set-value-to-input-web-element-using-selenium/35127217#35127217 – Shubham Jain Sep 25 '19 at 11:12
  • Possible duplicate of [C#: How to send key combination in selenium's Keyboard.SendKeys](https://stackoverflow.com/questions/26855809/c-how-to-send-key-combination-in-seleniums-keyboard-sendkeys) – Alexey R. Sep 25 '19 at 11:37

1 Answers1

-1

You could try pressing Keys.Backspace in a loop and see if that helps.

var length = element.GetAttribute("value").Length;

for (int i = 0; i < length; i++)
{
    webElement.SendKeys(Keys.Backspace);
    Thread.Sleep(100);
}

Also, I know you have tried Keys.CONTROL + "a" + Keys.DELETE. I have tried this solution in the past, but split onto separate lines, so that may be worth trying as well:

webElement.SendKeys(Keys.Control + "a");
webElement.SendKeys(Keys.Delete);
CEH
  • 5,701
  • 2
  • 16
  • 40