2022-11-25

Karate UI: Locating web elements on a HTML web page having multiple div tags with same ID?

My web app has a page displaying a .yaml file with key-val pairs, the yaml page has multiple(100+) tags having the same ID's for all the key-vals making it hard to locate the web element to update through the karate ui script.

Example of xpaths:

  1. key1: val1 //*[@id="ember5066"]/div[2]/div[6]/div[1]/div/div/div/div[5]/div[369]/pre/span/span[3]

  2. key2: val2 //*[@id="ember5066"]/div[2]/div[6]/div[1]/div/div/div/div[5]/div[373]/pre/span/span[3]

enter image description here

the below locator doesn't seem to work in this scenario

* string webElement = "//span[text()='abc']/following::span[text()='key1']//following-sibling::span"

Using the script syntax as below to update the value

script(webElement, "_.innerHTML='" + parameterized + "'")

Question: How to locate and update the value of the webElement or if there is a way to do indexing in karate?

Thanks in advance!

EDIT: @Peter Thomas
I am able to locate the element using this syntax:

  • def ele = locateAll('.classname')
  • def vals = ele.map(x => x.text)

Then print vals[40]
Is there a way to pass vals[40] to the 'input' syntax to be able to edit it in my tests?

Ex: * input(vals[40], 'test input')



No comments:

Post a Comment