1

I tried this Given select('select[name=data1]', '{}Option Two') for selecting the dropdown select. I can see the changes in the select tag, but when click the submit button, it resetted to the default option.

I both tried these solutions. Don't work.

* def envName = 'env-rab' * select('#environmentId', envName)

* script("document.getElementById('environmentId').value='" + env-rab + "'")

EDIT:

Change event triggered and the error message is :-

org.graalvm.polyglot.PolyglotException: js eval failed twice:(function(){ var e = document.querySelector("select[name=cars]"); var t = "Opel"; for (var i = 0; i < e.options.length; ++i) if (e.options[i].value === t) { e.options[i].selected = true; e.dispatchEvent(new Event('change')) } })(), error: [type: MAP, value: {type=object, subtype=error, className=TypeError, description=TypeError: Cannot read properties of null (reading 'options')
dinesh
  • 61
  • 5
  • depending on what kind of JS is on your page, there are many reasons. ui automation is hard, so the only advice I have is to figure this out, quite likely that some event should be triggered on the element my guess is`change` https://stackoverflow.com/a/60800181/143475 & https://stackoverflow.com/a/28324400/143475 – Peter Thomas Nov 17 '22 at 10:46
  • Yes. Change event is triggered. Also I checked those answers, can't get the things done. Can you please answer here. – dinesh Nov 17 '22 at 10:57
  • 1
    sorry I have nothing more to add here, I can try if you follow this process, basically we need to replicate this else we can keep guessing: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue – Peter Thomas Nov 17 '22 at 11:39
  • `mouse()` can work better for JS driven drop-downs: https://stackoverflow.com/a/76623198/143475 – Peter Thomas Jul 05 '23 at 18:43

0 Answers0