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.
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')])
opsValueLookup2 object would be: (//*[contains(@id, 'ops-valuelookup')])
These would be even more specific.
opsValueLookup1 object would be: (//*[contains(@id, 'ops-valuelookup') and @type = 'text'])
opsValueLookup2 object would be: (//*[contains(@id, 'ops-valuelookup') and @type = 'text'])
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.