[XPath] How could I clear the text box?

Hello everyone! Thank you for your help in my last post. Today I have another issue again, which is how to clear text in this XPath.

First of all, I am still practicing my testing on the Magento website and trying to create an updated item. In the end, I cannot solve the problem of clear text because before users can update the quantity of an item, they have to clear the text in the quantity field first, then click the “update” button.

In my code, I use xpath as //label[text()="Qty"]/following::input[@type = 'number'][1] and call WebUI.clearText(findTestObject('Object Repository/Bucket_List_Popup/Quantity_Textbox')) but it is nothing happen…

While I tried to use WebUI.sendKeys(findTestObject('Object Repository/Bucket_List_Popup/Quantity_Textbox'), Keys.chord(Keys.BACK_SPACE)) but missing some library that I am not sure what should I use…

Last but not least, thank you for your help again. I am happy to participate in this good community.

1 Like

You should highlight your text first in the textbox and then “delete” the whole text with the backspace, like below. I use this when WebUI.clearText() does not work.

import org.openqa.selenium.Keys as Keys
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WebUI.sendKeys(findTestObject('Object Repository/Bucket_List_Popup/Quantity_Textbox'),Keys.chord(Keys.CONTROL, 'a'));

WebUI.sendKeys(findTestObject('Object Repository/Bucket_List_Popup/Quantity_Textbox'), Keys.chord(Keys.BACK_SPACE))

Another method to remove text in a textbox is supposed to be like below, but I have never tried this one:

import org.openqa.selenium.Keys as Keys
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WebUI.sendKeys(findTestObject('Object Repository/Bucket_List_Popup/Quantity_Textbox'), Keys.chord(Keys.SHIFT, Keys.ARROW_UP))

WebUI.sendKeys(findTestObject('Object Repository/Bucket_List_Popup/Quantity_Textbox'), Keys.chord(Keys.BACK_SPACE))

1 Like

Thank you. It’s works! :star_struck: :pray: