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

huangapple go评论94阅读模式
英文:

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

问题

我正在尝试自动化搜索组合框中的项目,在这种情况下,为了访问结果列表,您需要首先输入字符(它充当研究和过滤工具)。

为了提供上下文,这是这个组合框的工作方式:
输入前
输入后

问题在于在尝试与组合框交互时,使用select()函数会失败,因为在我们尝试与组合框交互的时候,似乎还没有可用的结果列表。因此,函数的第二个参数不能为true
--> 例如select('myXpath', '{^}itemListName')或select('myXpath', 1),其中1是列表中项目的索引。

我还没有成功使click()函数在这种情况下工作,因为尽管karate报告中的步骤是通过/绿色/OK的,但机器人实际上没有单击框(输入区域不会出现),这会导致下一步(在输入区域中输入字符)失败。

您是否遇到过这种情况?您使用了什么方法来解决它?
谢谢您的帮助!

我尝试使用select('xpath','{^}nameOfItem')或select('xpath', indexOfItem)函数在span的不同级别和选择框上。
使用select('xpath', indexOfItem)获得的结果如下:
select函数错误

另外,无论我使用完整的XPath还是常规XPath(//*[@id="select2-SearchKey_ECS_code-container"]),错误都是相同的。

我还尝试使用click('xpath')函数点击选择框,但尽管karate报告中的步骤是绿色的(OK),机器人没有成功实际点击框(输入区域没有出现),这导致下一步失败:
点击函数的karate报告

英文:

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

答案1

得分: 0

基于您提供的jsfiddle,我成功使其工作。您可能不需要switchFrame步骤。

  • 驱动程序'https://jsfiddle.net/rpzxmg0u/'
  • switchFrame('[name=result]')
  • mouse('.select2').click()
  • input('body', 'Ap')
  • mouse('{li}Apple').click()

mouse() 的使用在这里解释: https://github.com/karatelabs/karate/tree/master/karate-core/#drop-downs

input('body', 'foo') 只是针对整个页面进行按键操作,在这种情况下有效。

英文:

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.

huangapple
  • 本文由 发表于 2023年7月13日 22:36:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76680593.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定