1

I have task when I want to press button with "Delete" caption according to string (picture attached). There are many these sections in application and I want to press the Delete button according to specific H6 string.

I need to write click action to find the code with H6 value (this time "app111") and click on the button Delete.

I have tried something like this "rightOf('app111').find('button').click() or below('app111').find('button').click()" in many variations but I was not successful.

In some cases (when the tags are in straight path works for me: click('{//*[normalize-space(text()) = \'' + appName + '\']/../../div/table/tbody/tr/td[2]/a[2]}'), but this time H6 and DIV are on the same level. Now the structure is (more on picture attached):

H6
DIV
  A
  DIV
    DIV
    A
    DIV
    A
    BUTTON
       SPAN

How to write button click according to H6 value (click on next "Delete" button after H6 with specific string)

Thank you for some help!

enter image description here

Radim Bukovský
  • 337
  • 2
  • 11

1 Answers1

1

Can you try near(): https://github.com/intuit/karate/tree/master/karate-core#near

Else I think you should write a little JS to get hold of the element. For some ideas, see this: https://stackoverflow.com/a/60800181/143475 and https://stackoverflow.com/a/60618233/143475

For example, I think once you select app111 which should be easy, you can get the div after it by getting element.nextSibling

Then you run querySelector('.btn-link') or something similar, and it should work.

Since you have pasted a screen-shot I can't help more, but if you can follow this process - I can take a look: https://github.com/intuit/karate/tree/develop/examples/ui-test

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Thank you for your answer and tips. I am not so skilled in JS, I have tried it using near(), but I suffer with syntax (I have tried some clicks but it did not work) e.g.: near('{h6}app111').find('button').click() Another way how to click on button should be select a class with "href=/applications/app111/" - then click on button - the link with the href is in row above the button. I have tried this but it does not work: 1) attempt: * near("//a[@href='/applications/app111/']").find('{}Delete').click() 2) attempt: * near("//a[@href='/applications/app111/']").find('button').click() – Radim Bukovský Apr 08 '20 at 15:53
  • 1
    This worked for me finally: click('{//*[normalize-space(text()) = \'app111\']/../div/div/button/span[normalize-space(text()) = \'Delete\']/..}') – Radim Bukovský Apr 09 '20 at 09:53
  • @RadimBukovský thanks for the update ! In the long term we hope `karate-robot` will give teams an easier way to do this: https://github.com/intuit/karate/tree/master/karate-robot – Peter Thomas Apr 09 '20 at 11:44