🍺 Join Clicknium for quality support, growth opportunities, and a supportive community


def clear_text(
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.

 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.



  • 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  

  • 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/")
What are your feelings
Updated on 29 August 2023