0

I have an issue that I am facing. I have a text in the text box that I want to delete, the problem is that

driver.find_element_by_id('foo').clear()

not work and I need something harder than this clear function that do nothing. I used this mthood that actually worked in windows:

element.sendKeys(Keys.CONTROL + "a");
element.sendKeys(Keys.DELETE);

if I want it to run on mac and on Linux machine, how can I perform it?

please the clear() not worked please do not provide solution with the clear() method

1
  • 1
    What tag is driver.find_element_by_id('foo')? Commented Jun 22, 2020 at 15:12

3 Answers 3

2

Use execute_script:

element=driver.find_element_by_id('foo'); driver.execute_script("arguments[0].value=' ';", element);

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

Comments

0
  1. try

    driver.findElement(yourelement).sendKeys("");

  2. or variant

    use Actions action = new Actions(driver);
    // ...  // may be move cursor to field
    action.sendKeys(Keys.ARROW_LEFT);
    action.build().perform();
    

may be problem in selenium library error, or in the webdriver version, or conflict with js-framework on a form?

Comments

0

i use this also

public void clearAndInputStringData(By locator, String text) throws Exception {
        ClickElementWhenClickable(locator);
        WebElement element = getWebDriver().findElement(locator);
       // element.sendKeys(Keys.CONTROL + "a");
        Actions actions = new Actions(getWebDriver());
        actions.doubleClick(element).perform();
        element.sendKeys(Keys.DELETE);
        element.sendKeys(text);
    }

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.