def clear_text(
self,
by: Union[Literal["set-text", "send-hotkey"], ClearTextBy],
clear_hotkey: Union[Literal["CAD", "ESHD", "HSED"], ClearHotKey] = ClearHotKey.CtrlA_Delete,
preaction: Literal["setfocus", "click"] = PreAction.SetFocus,
timeout: int = 30
) -> None
Clear text of the target element.
Parameters:
by: ClearTextBy
The method to clear text for the target element
set-text
: clear the target element’s text by setting its property.
send-hotkey
: clear text by sending hotkey to the target element. “clear_hotkey” and “preaction” parameters also need to be specified accordingly.
clear_hotkey: ClearHotKey
If by is set to “send-hotkey”, then specify hotkey with this parameter, default is CAD
.
CAD
means{CTRL}{A}-{DELETE}
: send the combined keys “{CTRL}{A}” first, then send “{DELETE}”.
ESHD
means {END}-{SHIFT}{HOME}-{DELETE}
: send “{END}” first, and send combined keys “{SHIFT}{HOME}, then send key “{DELETE}”.
HSED
means {HOME}-{SHIFT}{END}-{DELETE}
: send “{HOME}” first, and send combined keys “{SHIFT}{END}, then send “{DELETE}”.
preaction: PreAction
If by is set to “send-hotkey”, specify this parameter for the action to be taken before sending hotkey to clear text.
timeout: int
Timeout for the operation, the unit is second, and the default value is 30 seconds.
Returns:
None
Example:
- Desktop file “Save As” dialog
For the file “Save As” dialog, use clear_text to clear the existing content in “File name” input box, the by can be set to “set-text” in this case.
from clicknium import clicknium as cc, locator, ui
ui(locator.chrome.edit_1001).clear_text(by="set-text")
- Wechat message input box
This type of UI element does not support “set-text” to clear text, then use the following way.
from clicknium import clicknium as cc, locator, ui
ui(locator.wechat.edit1).clear_text(by="send-hotkey", clear_hotkey="CAD", preaction="click")
- Web input textbox
chrome_tab = cc.chrome.open("https://contoso.com/")
chrome_tab.find_element(locator.chrome.contoso.text).set_text("hello")
chrome_tab.find_element(locator.chrome.contoso.text).clear_text(by=ClearTextBy.SetText)