Locating objects via id?

Hello All,

I am looking for help on ways to use the following to locate objects.

//*[@id=‘btn-login’][@type=‘submit’]

Below is what I am trying to locate, however even though they all have ids none are able to be located.

Node groups

Any help would be much appreciated.

Thanks :slight_smile:

Are the id static or dynamic?

The ids are static. As far as the g I have no idea.

I have not encountered a g tag so I let you do your reading on it.

To get a pathway to an element with an unique id, you should be able to get it either:

// you can write pathway this way only for id attribute
id("560")

or

// normal pathway writing for all other attributes
//*[@id="560"]

Yes I have tried both of these methods, but I cannot seem to get them to work or I just dont know where to enter them correctly. Could you send a screenshot of where in Studio to put this information. I have tried editing the attributes of the Obj. but it doesn’t seem to make any difference.

Please post more of the HTML - specifically, what HTML surrounds the <g> elements?

I think your page uses Anglular – correct?

1 Like

I assume you use the Object Repository. Find your element in the OR, delete the extraneous attributes except tag and xpath. Fix your xpath like you need (as above) and try again.

@josh.meeks, you may also want read these posts from @Russ_Thomas:

1 Like

Thank you very much for the information. I was able to locate one object not related to the above but one is a start. I am trying to locate using class and id but this is always the result.

Unable to find the element located by ‘By.xpath: //*[@class = ‘node-group ng-tns-c721-119 ng-star-inserted’ and @id = ‘560’]’. Please recheck the objects properties to make sure the desired element is located. Any ideas?

The id attribute is supposed to be unique, so that should be enough to identify your element. If you want the class also, then perhaps use only part of it, like:

 //*[contains(@class, 'c721-119') and @id = '560']

I agree. The id is a unique value. Thats why I am so confused as to why I cannot get this to work. We have thousands of these elements and all have unique values attributed to them. I can locate things by title without issue now thanks to the post @dave.evers, but id still seems to be an issue.

My main issue is that while we have thousands of these obj. there may be multiple with the same title thus id is the best way to locate these objs. While Katalon seems to be able to find the objs using relative position and some form of normalize.text or something i would think it an easier job for the program and myself if I was able to locate by the id.

The following doesn’t seem to work either:

Unable to find the element located by ‘By.xpath: //g[@id=“560”][count(. | //[@class = concat(" //[contains(@class, " , "’" , “c721-119” , “'” , ") and @id = " , “'” , “560” , “'” , “]”) and (text() = ‘Stage 1’ or . = ‘Stage 1’)]) = count(//[@class = concat(" //[contains(@class, " , “'” , “c721-119” , “'” , ") and @id = " , “'” , “560” , “'” , “]”) and (text() = ‘Stage 1’ or . = ‘Stage 1’)])]'. Please recheck the objects properties to make sure the desired element is located.

You are making it way too complicated. Just go with id or text but don’t get so complicated.

//g[text()="Stage 1"]

or

id("560")

Also, read up on the g tag to see if that could be anything.

This is the obj I am trying to find.

Interesting what action does the [1] or [2] perform?

Something like this might work…
If there are 5 SameTitle labels on the page it picks the one you want…
For example (//*[(text() = ‘SameTitle’)])[3] will pick the third one.

(//*[(text() = 'SameTitle')])[1]
(//*[(contains(text(), 'SameTitle'))])[1]

For the same input types I use something like this:

(//input[@type='text'])[1]
(//input[@type='text'])[2]
(//input[@type='text'])[3]

You can use @Dave_Evers idea of using arrays like he has shown you, or can also use the array indicator in another way, like:

id("560")/svg[1]//mat-card[1]/mat-card-title[1]

What this means is to start at the unique id, then move down to the first child svg tag, then notice the double slashes, this just jumps down the HTML “tree” to the first child mat-card tag, and then finally down to the first child mat-card-title tag.
Where this could have concerns is if there are more than one “foreignObject” tags at the same level (where I jumped over). If there is more than 1, then change the double slash to /foreignObject[1]/

The whole idea is to create an unique pathway.

Edit: should you need to use it, there is an array usage that allows you to jump to the last child tag, such as …mat-card-title[last()]. Or second-to-last …mat-card-title[last()-1]. :slight_smile:

So I think I got it figured out.

This seemed to work: //*[@id = ‘566’]//mat-card-title[(text() = ‘Stage 3’ )]

Thank you all for your amazing help with this. I am more than positive I will be posting other ridiculous newbie questions :slight_smile: