This method works on text elements such as editbox etc. It clears the existing text.It doesn’t take any argument and it doesn’t return anything.
Syntax :
ele = driver.find_element(AppiumBy.CLASS_NAME,"Locator_Value") ele.send_keys("text_to_enter") ele.clear()
Example : In the below example we are launching the app on an Android device and sending text on an edit box using the Class Name locator and clear the text in the edit box.
SendTextAction.py
from appium import webdriver from appium.webdriver.common.appiumby import AppiumBy # Step 1 : Create "Desired Capabilities" desired_caps = {} desired_caps['platformName'] = 'Android' desired_caps['automationName'] = 'UiAutomator2' desired_caps['platformVersion'] = '10' desired_caps['deviceName'] = 'Pixel3XL' desired_caps['app'] = ('/Skill2Lead/Appium_Demo_App/Android/Android_Appium_Demo.apk') desired_caps['appPackage'] = 'com.skill2lead.appiumdemo' desired_caps['appActivity'] = 'com.skill2lead.appiumdemo.MainActivity' # Step 2 : Create "Driver object" driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps) # Step 3 : "Click on the button using ID locator value" ele_id = driver.find_element(AppiumBy.ID,"com.skill2lead.appiumdemo:id/EnterValue") ele_id.click() # Step 4 : Wait for 2 seconds time.sleep(2) # Step 5: Enter the text in editbox ele_classname = driver.find_element(AppiumBy.CLASS_NAME,"android.widget.EditText") ele_classname.click() ele_classname.send_keys("Skill2Lead") # Step 6 : Clear the entered text ele_classname.clear() time.sleep(2) driver.quit()