Clear or Remove value from the list

Hello team,
I have used Press Keys and selected China from the list and below is the script
Press Keys xpath://div[contains(text(),‘Click to view countries and regions’)] China

Now I want to unselect or Remove selected China from the list …So what keyword I should use for this ?

I have tried below:
Press Keys xpath://div[contains(text(),‘Click to view countries and regions’)] China
Press Keys None RETURN
Then I am getting below error:
20210604 13:38:46.460 : INFO : Sending key(s) ("’’",) to xpath://div[contains(text(),‘Click to view countries and regions’)] element.
20210604 13:38:46.602 : INFO :
20210604 13:38:46.606 : FAIL : Element with locator ‘xpath://div[contains(text(),‘Click to view countries and regions’)]’ not found.
Ending test: EIQ Access.TS1.Test1

Hi Satish,

Without knowing anything about your application, i’ll take a guess:

Press Keys    xpath://div[contains(text(),‘China’)]    China

Quite likely is that once you selected China, the the element you are trying to interact with no longer contains the text ‘Click to view countries and regions’ as this has now been replaced by the text ‘China’.

Selecting China my not unselect either so you may need to choose another country to select, i.e. you might need:

Press Keys    xpath://div[contains(text(),‘China’)]    United Kingdom

or maybe even you could try (but I’m not sure if this option will be available again?):

Press Keys    xpath://div[contains(text(),‘China’)]    Click to view countries and regions

Hope this helps,

Dave.

Hi Dave, Thanks for your reply.
I have selected China first and then I want to select another country …
In my application , I can select up to 3 countries at one time ,
But my case is , I have selected one country China and then I want to remove or clear the China and then select India .
image

Hi Satish,

Ah, ok, now I see what you mean, you will need to find the xpath to the ‘x’ next to the country name ( China x )

I’ll guess that the blue element that contains the country is a div and the text of the country is a span and the x is a hyperlink, both contained inside the div, based on these guesses the xpath could look like this:

Clcik     //div/span[text()=="China"]../a

You’ll need to adjust that based on what the actual html looks like and you could use a parameter in place of the word China if you want to create a keyword called something like “remove country”

Hope that helps,

Dave.

Hi Dave,
Thanks for the reviewing my questions and for the reply.
Finally it works now. I am using below keyword to remove / clear the value.
Press Keys //div[./label[contains(text(),‘Select up to three countries and regions’)]] BACKSPACE

That backspace will remove the last item in the list, if you only have 1 country selected no problem, but if you selected multiple countries and the application sorts them then you might get unexpected results (remove a different country than you were expecting) especially if the sort order changes from one release to the next.

Something to be aware of as you expand the scope of your test cases.

Good luck with your project.

Dave.