1

I'm regularly hitting odd visible page text that karate cannot see, likely due to some funky JS magic that I don't fully understand.

Example image shows text on the page generated after clicking on a translate button: enter image description here I'm trying to assert that the translated text is present and correct on the page.

This is the selector: #results-panel > div > div > div.thread > div > div.activity.panel.panel-default > div.panel-content > div > div:nth-child(2) > div:nth-child(1) > div > div.analysedText-translation > div > span:nth-child(3)

Example snippet of the element: enter image description here

Using the wildcard {} or {^} doesn't work. eg waitFor('{^}A few random things about cats') returns a null

I played around with CSS selectors and am able to highlight the text using:

  • highlight('.analysedText-translation > div > span:nth-child(3)')[0]

I was thinking maybe using waitForText but not sure how to apply it. Any suggestions?

Puti
  • 101
  • 8

1 Answers1

1

The reason the docs don't talk much about CSS selectors is that it is a standard. BTW this is open source, you are welcome to contribute pull-requests to improve the documentation.

UI automation is hard, I'm not going to claim that any framework makes it magically easier.

Suggestions:

If still stuck, follow this process so that we can fix anything in the framework if needed: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Wow you are fast at responding! I edited by post before I saw your response to remove the CSS mentioned. Yes, I'm using the debugger which works great. I'm able to traverse Chrome devtools to locate the element in console. Would the tree walking be better than using the actual CSS selector? – Puti Jan 06 '21 at 04:16
  • 1
    Also, apologies if I offended with the CSS part. I understand that's it's standard. Please don't take any offence, this is a great thing you've made. I'm just trying to learn and navigate it's nuances...some of which aren't immediately obvious to me. – Puti Jan 06 '21 at 04:19
  • @Puti a lot depends on the page and the JS. but since the tree-walking uses JS behind the scenes, it may be more robust. note that you can do things like `locateAll('div')` and then loop over the results, get attributes and find what you want. there are many ways – Peter Thomas Jan 06 '21 at 04:20