XClickText - exact text match not possible

I have an issue recognizing the exact text match with XClickText. As I have some very similar lines I need an exact text match.
Here is what XClickText finds with the given search strings in below website:
-) “Aktionskurs -20% Guten Morgen Yoga - 13.01.-24.02. (7 Wochen) STUDIO” > I need to find this string but it finds nothing
-) “Aktionskurs -20% Guten Morgen Yoga” > finds a text but is not sufficiently identifying the line.

I tried to replace “.” and “-” with “?” but it does not work. How can I solve this?

Thanks for any advice.

why do you use “XClickText” ?
I would just go with “click” and use xpath

The reason why I need to do this is related to another issue that is described here: Webscraping - find Locator related to a textsearch - #5 by admin.
Therefore I need to use XClickText.

Here is the OCR overlay. I can search for the strings 1 and 3. When I search for string 2 it cannot be found. I’m stuck :unamused:

ORC commands and any command with X like XClick are extremely unreliable and slow commands. I would always stay away from those.

There should be a way to identify the locator. Can you post the html code of that portion you try to locate? I’m also not sure what you mean identify the locator.

Get Value of a specific Tag Attribute:

< th scope=“row” >
< a href=“/003A000000qaIZ7?srPos=0&srKp=003”
data-seclke=“Contact”
data-seclkh=“804d175c78930e8ffe5889584a57d259”
data-seclki=“003A000000qaIZ7”
data-seclkp=“/003A000000qaIZ7”
data-seclkr=“1”
onmousedown=“searchResultClick.mousedown(this, event)”>Berta Abramovich< /a>
< /th>

xpath=//*[@id=“Contact_body”]/table/tbody/tr[2]/th/a@data-seclki
→ 003A000000qaIZ7

“Command”: “storeAttribute”,
“Target”: “xpath=(//div[@id=‘UCSF_EDS_People__c_body’]/table/tbody/tr[${myRecordIndex}]/td[4]/a)@data-seclkp”,
“Value”: “myEDSPeopleUserID”,
“Description”: “”

ANOTHER EXAMPLE

< span class=“plugin_pagetree_children_span” id=“childrenspan618632942-0” >

“Command”: “storeAttribute”,
“Target”: “xpath=(//ul[@id=‘child_ul398657825-0’]/li/span)@id”,
“Value”: “myPageID”,
“Description”: “”

→ childrenspan618632942-0

Note: these are examples I used in my own scripts. The beginning of the xpath expressions referencing to HTML that is does not shown here.

Hi @noahhath ,
I fully agree that OCR/XClick ist unreliable. I need to find one of the following texts and then click on it. For example the two marked lines have following locators:

  1. I need to search for the text “Aktionskurs -20% Guten Morgen Yoga - 06.05.-24.06. (7 Wochen) STUDIO”,
  2. derive the locator “xpath=//*[@id=“filter-event-products”]/div[2]/div/div[2]/div[2]/table/tbody/tr[37]/td[2]”,
  3. click on the locator.

Instead of using any xpath=(//*[@id… use the tag where that id is imbedded for example if it is < td> so you haver a more accurate targeting in case there are other tags with the same ID
xpath=(//td[@id=“filter-event-products”])…

If you need to click on each of them:
1.Count the tags
{
“Command”: “storeXpathCount”,
“Target”: “xpath=(//td[@id=“filter-event-products”]))”,
“Value”: “myNbrOfRows”,
}

  1. Click on them on by one using the times command
    You want to target the following tags like first, second, third
    xpath=(//[@id=“filter-event-products”])[1]
    xpath=(//
    [@id=“filter-event-products”])[2]
    xpath=(//*[@id=“filter-event-products”])[3]

using
times myNbrOfRows
click xpath=(//td[@id=“filter-event-products”])[{!time}]
end

Hi @noahhath ,
its clear how to click on the lines as you described using the line number:
image

The problem is that I don’t know the line number to click on. Therefore I have to read the text upfront (the content is dynamic), e.g. “Aktionskurs -20% Guten Morgen Yoga - 06.05.-24.06. (7 Wochen) STUDIO”, then identify the corresponding line number and then trigger click xpath=//*[@id=“filter-event-products”]/div[2]/div/div[2]/div[2]/table/tbody/tr[37]/td[2].

So I need to read the text and identify the corresponding line number/locator/xpath.

is there a link to the website I can go to check?
Or a website that is similar?
Maybe I can come up then with the code. I might miss something here.

Hi @noahhath , it’s a private website. If we can have a MS Teams or Zoom call I can show you.

can you save that page as HTM or the portion of the code as HTM and post it here?

Hi @noahhath , please finde the HTM attached.
Yogagalerie - Erstellung von Abrechnungsmethoden - Eversports.zip (49.9 KB)

Hi, unfortunately I can not run kantu scripts on html pages stored on the hard drive so I could not test the current script but this might give you some hints:
This is the HTML code you have to look at. It’s shows up as often as you have check boxes to click:

< div class=“admin-checkbox u-mb-0” >
< input data-selector=“event-activity617460” type=“checkbox” class=“select-item select-single” >
< span/ >
< /div >
< /td >
< td>Aktionskurs -20% Guten Morgen Yoga - 06.05.-24.06. (7 Wochen) STUDIO < /td >
< td >Aktionskurse< /td>
< td>Kurs< /td>

  1. Find out how many checkboxes we have to click by counting the occurrence of the exact word “Aktionskurse” in the TD tag < td >Aktionskurse< /td>: xpath=(//td[text()=‘Aktionskurs’])
  2. For each occurrence click the checkbox. Identify the textbox by the following criteria:
    a. its’ a < input> tag
    b. that input tag holds a data-selector that starts with the word “event-activity”
    c. That input tag also has a type=“checkbox”
    d. That input tag also has a class=“select-item select-single”
    → xpath=(//input[starts-with(@data-selector,‘event-activity’) and @type=‘checkbox’ and @class=‘select-item select-single’])[1]
    That should point to the first instance of the checkbox
    To point to the second checkbox instance you have to increase the index
    → xpath=(//input[starts-with(@data-selector,‘event-activity’) and @type=‘checkbox’ and @class=‘select-item select-single’])[2]

You do that in a “times” loop. So the code would look something like that. I could not really test it but should be close to what you need.

{
“Command”: “storeXpathCount”,
“Target”: “xpath=(//td[text()=‘Aktionskurs’])”,
“Value”: “myAktionskursNbr”,
“Description”: “”
},
{
“Command”: “times”,
“Target”: “${myAktionskursNbr}”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “click”,
“Target”: “xpath=(//input[starts-with(@data-selector,‘event-activity’) and @type=‘checkbox’ and @class=‘select-item select-single’])[${times}]”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “end”,
“Target”: “”,
“Value”: “”,
“Description”: “”
}

I hope that helps. Please let me know.

Hi @noahhath , I had a look at your proposed solution. Not sure if I understood it correctly.
I need to click only one specific occurency of the entries not all of them, e.g. only “Aktionskurs -20% Guten Morgen Yoga - 06.05.-24.06. (7 Wochen) STUDIO”. So how do I know for the “click” command the “x”: “xpath=//*[@id=“filter-event-products”]/div[2]/div/div[2]/div[2]/table/tbody/tr[$x ]/td/div”?

The solution I worked with up to now is to loop through the items:
“xpath=//*[@id=“filter-event-products”]/div[2]/div/div[2]/div[2]/table/tbody/tr[$times]/td/div” and to extract the corresponding text value via “storeText” and compare it to the text I search for, e.g. “Aktionskurs -20% Guten Morgen Yoga - 06.05.-24.06. (7 Wochen) STUDIO”.
But this solution is too slow. I takes alot of time to loop through all the element. I have pages with more than 100 elements and in order to find several text elements it all takes too much time and is additionally not stable enough. So I was searching for a method where I can do it the other way round. Instead of looping through the locators and reading the text > search for the text and derive the locator.

ok, so then what is your identifier to click it? How from the human point of view do you decide which one to click? Is it always the first one to click from the list or the one that always says “Aktionskurs -20% Guten Morgen Yoga - 06.05.-24.06. (7 Wochen) STUDIO”?

I have an Excel Sheet that I upload that tells me which one to click.

what is then one of the values that comes from the excel sheet to tell you what to click?

The value that comes from the excel is: click on “Aktionskurs -20% Guten Morgen Yoga - 06.05.-24.06. (7 Wochen) STUDIO”.

OK,

This is your HTML below and you want to target the < input> tag to click

< tr data-item=“…Aktionskurs -20% Guten Morgen Yoga - 06.05.-24.06. (7 Wochen) STUDIO…” …>
< td style=“width:30px;”>
< div class=“admin-checkbox u-mb-0”>
< input data-selector=“event-activity617460” type=“checkbox” class=“select-item select-single”>
< span/>
< /div>
< /td>

  1. We identify the unique text of this this link (inside of the < tr> tag and the ‘data-item’ identifier )
  2. and then parse down the root

{
“Command”: “click”,
“Target”: “xpath=(//tr[contains(@data-item,’ 06.05.-24.06.')])/td/div/input”,
“Value”: “”,
“Description”: “”
},

Again I can not test it but it should be close if it is not already working.
Hope it helps

This is the solution :blush: . Didn’t know this is possible. Thanks alot for your help and especially your persitence :+1: