This is regarding the case when there are same kind of elements on the same page but under different headers, e.g in below the below screenshot the values for ‘Date from’ and ‘Date to’ are autopopulated and user needs to enter the highlighted value. Using object spy the name of the elements comes to be same and position, ID is different. I dnt want to use ID because of its dynamic nature and Postion does not work.
Don’t use the Spy, don’t rely on the Record tool. The tool gets you started, but doesn’t help much. The Test Objects generated by the tools tends to fail (wrong, unfortunate, … ). You have to correct them manually. In order to correct them, you must train yourself for XPath or CSS Selector technology by reading some good tutorials.
E.g,
Unless you learn the basics of XPath and/or CSS Selector, you wouldn’t be able to be productive with Selenium
Hi @shrutis, As Kaz pointed out learning the basics will help you in the long run.
But for now you can also try…
opsValueLookup1 object would be: (//*[contains(@id, 'ops-valuelookup')])[1]
opsValueLookup2 object would be: (//*[contains(@id, 'ops-valuelookup')])[2]
These would be even more specific.
opsValueLookup1 object would be: (//*[contains(@id, 'ops-valuelookup') and @type = 'text'])[1]
opsValueLookup2 object would be: (//*[contains(@id, 'ops-valuelookup') and @type = 'text'])[2]
Although you say the id attributes are dynamic, you can start your pathway on another element that has some text or stable attribute and move from that element to the one you want. An example could be:
In order to answer to a question “tell me a XPath expression that correctly point to an HTML element which is … (with some tricky condition)” , we always need to see the whole HTML source of the target web page (line#1 to the end). I would write whole HTML for short of this.
Well, I am afraid, @grylion54 was too kind. I am sure, @grylion54 could not see the whole HTML of the @shrutis’ target web page. He made a wild guess how the whole HTML could be, and presented an fake example. But, I guess, @shrutis would not understand what @grylion54 meant deep in his head.
You can see the whole HTML of your target web page, but others in this forum can’t. You should be aware of this handicap. You may expect that somebody can tell you a correct answer without looking at the whole HTML. No, it is too difficult. You need to share the whole HTML publicly to be answered.
How to share the whole HTML? — You can save the whole HTML as one file using Google Chrome. Once saved, you can attache the file to your forum post.
open your target HTML in Chrome browser. For example, http://example.com
Right-click anywhere of the page in the Chrome window, choose the menu “Save as …”
Please attache the file here in the Katalon user forum if possible.
They can open the MHTML file with Chrome, then they will see a complete replication of the web page.
Are you concerned about security? Does your organization require you not to disclose the whole HTML source to others? ---- In that case, you can’t share the file, of course.
In such case, you can not ask a good question in any public forum. Guys would not be able to help you without information. You have to solve your problem just for yourself.
Could you please try parent-child relationships. Sometimes , you can navigate to an element by locating its parent element first and then accessing the desired element within it.