selenium clear() command doesn't clear the element

前端 未结 8 1230
旧时难觅i
旧时难觅i 2021-01-11 21:14

I have been writing selenium scripts for a while in Java. I encountered a very weird issue today.

Here is the issue: I cleared a text field using webelement.clear()

相关标签:
8条回答
  • 2021-01-11 22:00

    It's possible that the fields you're trying to fill has autocomplete attribute set to on. [Reference]

    If clear() works when the line executes then it's safe to say that this is not a webdriver specific issue.

    It would help if you can show the html snippet of the page section you're working on.

    Possible areas of debugging:

  • forcefully remove autocomplete attribute on page load using java script executor
  • turn off autocomplete setting on the driver level. I believe the solution would vary depending on the driver being used.

    Good luck!

    PS: Those Thread.sleep(s) are not advisable.

0 讨论(0)
  • 2021-01-11 22:03

    Another way that worked for me in python, but is not what you would call elegant:

    for _ in range(4):
        risk_percentage.send_keys(Keys.BACK_SPACE)
    
    0 讨论(0)
  • 提交回复
    热议问题