What does WebElement.clear() Do to TextBoxes?

前端 未结 2 786
梦如初夏
梦如初夏 2020-12-20 12:21

I\'ve recently run into a problem working with selenium where calling clear() on a custom text box causes issues when entering text later in the test. The text

相关标签:
2条回答
  • 2020-12-20 12:26

    The clear() method executes an "Automation Atom", which is a JavaScript function intended to provide the smallest basic unit of automation functionality for a browser. In the case of clear(), that function sets the value property of the element to an empty string (''), then fires the onchange event on the element. The atoms function you're interested in is bot.action.clear()

    0 讨论(0)
  • 2020-12-20 12:39

    Here is what exactly clear() will do. The function will clear textbox value and enable text box. Before entering text in text field we need to clear the text field and will enable it. If we do not use clear (), we can't enter any value in text field using selenium.

    driver.find_element_by_xpath(xpath).clear()
    driver.find_element_by_xpath(xpath).send_keys("data")
    
    0 讨论(0)
提交回复
热议问题