Search code examples
automationcomboboxkarate

Karate framework: How to select an item from a combobox needing to input characters first before the list of results is available?


I'm trying to automate searching items in a combobox where, in order to have access to the list of results, you need to input characters first (it acts as both a research and a filter tool).

For context, this is how this combobox works: before input after input

The issue is that using the select() function on this box fails because, seemingly, there is no list of result avalable yet, at the time we try to interract with the combobox. Therefore, the second argument of the function can't be true --> for example select('myXpath', '{^}itemListName') or select('myXpath', 1), 1 being the index of the item on the list

I also didn't manage to make the click() function work in that situation, because while the step is at pass/green/OK on the karate report, the robot doesn't actually click on the box (the input zone doesn't appear), which causes the next step (input characters in the input zone) to fail.

Have you ever been in this type of situation? What approach did you use to solve it? Thanks for your help!

I've tried to use the function select('xpath','{^}nameOfItem') or select('xpath', indexOfItem) on different levels of the span and on the arrow box for the selection.

This is the result obtained using select('xpath', indexOfItem): select function error

Btw, whether I use full Xpath or the regular one (//*[@id="select2-SearchKey_ECS_code-container"]), the error is still the same.

I've also tried to use the function click('xpath') on the selection box but while the step is green (ok) on the karate report, the robot didn't manage to actually click on the box (the input zone didn't appear) which causes the following step to fail: karate report on the click function


Solution

  • Based on the jsfiddle you provided, I was able to get this to work. You may not need the switchFrame step.

    * driver 'https://jsfiddle.net/rpzxmg0u/'
    * switchFrame('[name=result]')
    * mouse('.select2').click()
    * input('body','Ap')
    * mouse('{li}Apple').click()
    

    The use of mouse() is explained here: https://github.com/karatelabs/karate/tree/master/karate-core/#drop-downs

    And input('body', 'foo') just targets the whole page for key-presses, which works in this case.