Clear TextField rather than append

久未见 提交于 2019-12-13 18:39:07

问题


I'm using the following statement to clear text filed value:

input.value("abc")
input.value("")
input.value("def")

But, instead of clearing and set new value, it is appending the new value to old value. ('abcdef').

Is there any way to clear the TextField, before setting new val?


回答1:


You can clear using the selenium element:

input.firstElement().clear()

And you can send keys using << like so:

input << "abc"



回答2:


You can use the selenium Keys to backspace the texts that you already had entered. You can try many different ways to accomplish that. Here is a simple way to do that:

import org.openqa.selenium.Keys

input.value("abc")
input.value(Keys.chord(Keys.CONTROL, "A")+Keys.BACK_SPACE)
input.value("def")

It should do the job. Let us know whether it worked for you or not!

Cheers@!



来源:https://stackoverflow.com/questions/25946779/clear-textfield-rather-than-append

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!