Kantu is not clicking the button

Hi all

I am new to Kantu and am not a programmer by any chance.

I have a very simple set of instructions that I want Kantu to perform.
It keeps stopping on the one command as if it could not find the button/element.

  "Command": "clickAndWait",
  "Target": "//*[@id=\"ajaxcontent\"]/fieldset[2]/table/tbody/tr[3]/td[3]/table/tbody/tr[5]/th/a/span",
  "Value": ""

Basically it is the 15th button in a set of “identical” buttons.

There are 2 x “fieldset” and I did try to record a macro by clicking on a similar button in the 1st group and the only difference was it was " fieldset[1]", the rest was the same.

“Command”: “clickAndWait”,
“Target”: “//*[@id=“ajaxcontent”]/fieldset[1]/table/tbody/tr[3]/td[3]/table/tbody/tr[5]/th/a/span”,
“Value”: “”

All the text for the button is the same only the “onclick” is different.

I did google and tried this:

“Command”: “clickAndWait”,
“Target”:WebElement button = driver.findElements(By.cssSelector(“button[title=Attack this enemy now!][onclick*=fight?enemy=53]”))

I did inspect the button and it came up with this.

onclick=“l(“fight?enemy=53&friend=0&s=cc19f”,null,null,true)” class=“button ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only” style=“color:black” role=“button”>Attack this enemy now!

I also tried xpath=(//a[contains(@class, ‘Attack this enemy now!’)])[15]

Can you please advise me if my syntax or command is correct.

In iMacros all it did was click on the 15th button with that text.

Is there is an equivalent command for this in Kantu?

Thank you
Ken

Do you have a link to the website, or at least a screenshot?

Hi Ulrich

Thank you for replying. I have the following:

This is the URL https://apps.facebook.com/newperfectwarrior/?path=npc

This is the image
I basically want it to click the 15th instance of “Attack this enemy now!” from Minotaur.
If I can send the URL that will be even better.
So part of the onclick changes so I would think it needs a dynamic “button”
onclick=“l(“fight?enemy=53&friend=0&s=cc19f”,null,null,true)
The s=xxxx that part changes but the fight?enemy=53 stays the same always
The s= part is linked to the time.

Thanks for the screenshot. If iMacros TAG works, then I am 100% sure that there is an XPath that works as well…but at least right now I have no time to figure this out now :wink:

The much easier solution is to use xclick with relative image matching. So it finds the image of word “Minotaur” and then clicks whatever the pink box marks, in our case that is the button.

If you use this approach, just make sure that the “Minotaur” word and button is visible in the browser. You can do this by using first a CLICK on anything nearby => it scrolls this part of the page into view.

Hi ulrich.
I did try the relative image as you have shown even setting up the green and pink box. I was breaking at that point also. Maybe cos my green box was the entire image and not just part of the image. I will retry that.
I did see an xpath somewhere … yes I tried Selenium and this is what I saw while testing it. Below is the screen shot I took of that exact command that Seleium has. It also breaks at that point.
My entire “script” is quite long, the rest works just this one portion.

image

I see selectFrame on top of xclick: The good thing with XClick (image) is that you don’t need a selectFrame command anymore, since it works visually. On the other hand, the command does not hurt either :wink:

I guess the reason for it not working is this: Your ONV…dpi_120.png image and the green/pink boxes you have drawn looks good. But the image file name is missing _relative at the end. The relative feature (= looking for green and pink boxes inside input image) is only activated when the image file ends with _relative.

Solution: Just rename your image to ONV....dpi_120_relative.png and it should work.

I will remove the select frame as well. That was from the original recording and since I was only changing the one line I was not sure if I needed that.

Ok Yes I took the relative tick off thinking it did not matter. Ok I will redo that selection.

So it does click but not in the correct spot. I think the easiest is for the macro to find the 15th instance of “Attack this enemy now!” and click that button.
Can Kantu not recognise text strings and just count them till it finds number 15?

Thx

I guess what you mean is something like this (from your post above):
xpath=(//a[contains(@class, ‘Attack this enemy now!’)])[15]

That does not work in Kantu yet but I have heard that it will be supported soon. I asked support about exactly this last week :wink:

Kantu can also count text strings visually with the ocr feature.

xclick | ocr=Attack this@pos=2

Here is what I see with 3 enemies. It works well. In your case, since you have a much bigger list of enemies, you first need to scroll down to a place nearby, so the button you need is visible in the browser.

The OCR feature is easy to use. The one drawback with OCR is that it is rather slow. It takes a few seconds to OCR the image. That is why I reuse the x/y coordinates !ocrX and !ocrY for the next xclicks, so I have to run OCR only once :wink:

Here is my macro that attacks the zombie in a loop. :smiley:

After finding the right x/y with OCR, it simply keeps using this value, since the page does not change.

{
  "Name": "zombie",
  "CreationDate": "2019-2-2",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://apps.facebook.com/newperfectwarrior/?path=npc",
      "Value": ""
    },
    {
      "Command": "pause",
      "Target": "1000",
      "Value": ""
    },
    {
      "Command": "comment",
      "Target": "Run OCR to find text. This also sets !ocrX and !ocrY",
      "Value": ""
    },
    {
      "Command": "XClick",
      "Target": "ocr=Attack this@pos=2",
      "Value": ""
    },
    {
      "Command": "label",
      "Target": "zombieloop",
      "Value": ""
    },
    {
      "Command": "open",
      "Target": "https://apps.facebook.com/newperfectwarrior/?path=npc",
      "Value": ""
    },
    {
      "Command": "pause",
      "Target": "1000",
      "Value": ""
    },
    {
      "Command": "comment",
      "Target": "OCR costs time, so we just reuse the values from the first OCR run. ",
      "Value": ""
    },
    {
      "Command": "XClick",
      "Target": "${!ocrx},${!ocry}",
      "Value": ""
    },
    {
      "Command": "gotoLabel",
      "Target": "zombieloop",
      "Value": ""
    }
  ]
}

This looks to me that the page was still scrolling when you did the image search. So by the time the image and location was found, the page and buttons have already scrolled to a different place.

Solution: After you trigger the scrolling, and before you do the XClick, add a small PAUSE | 2000 statement. This way the scrolling is done when the image recognition starts.

Thank you with the pause all is sorted out.

Thank you very much for all your help.