1

I have try to press the delete key using below command but it doesn't reflect anything!

element = driver.findElement(By.cssSelector((#DeleteThis)));
element.sendKeys(Keys.DELETE);
1
  • Share the HTML code , and error stack trace if any ? Commented Jul 29, 2019 at 9:00

2 Answers 2

1

You need to build an action and the send it, the send keys is bound to actions not elements, example :

Actions action = new Actions(yourDriver);

action.sendKeys(Keys.DELETE).build().perform();

This will simulate pressing "delete" from your keyboard

In case you have the element delete (as from your example) and you need to click it, you just perfomr the click action on the element.

Sign up to request clarification or add additional context in comments.

Comments

1

Ok to do so, you need to use the delete command, kindly use the below code to perform the same. If it doesn't work first try to select it, as mentioned below.

To delete it use below code:

 WebElement ele = driver.findElement(By.cssSelector("#DeleteThis"));

 ele.sendKeys(Keys.chord(Keys.DELETE));

OR

Have you tried to first select it and then delete it?

Use below code, it will first select the element and then delete it.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.