How to select an element whose id/number is dynamic and keeps changing
I have a number that comes to my email that I would like to copy and save but the number keeps changing all the time.
If I take the xpath it will contain that number (
//b[contains(.,'821016')]) and I can't use anything from the source (at least I think I can't):
Can I use the location to copy the random numbers with CSS or maybe some kind of 0-9/* functions or any other suggestions?
And I need only the dynamic number, I got it to copy both through
getTextbut I can't paste. I get the following error when I try:
Exception in thread "main" java.lang.IllegalArgumentException: Keys to send should be a not null CharSequence
Laycee last edited by
You can use
as TushaGT suggests
However this will easily lead to problems if:
- you have more than one table
- you have more than one td (almost certain)
- you have td's with more than 1 span
Usually one looks for id's or classes or surrounding nodes that can be used, however there is none in your case.
In fact the HTML you are showing is so 'bare' I actually think you have two options in this situation:
- get the developer to add the tags
- use the full xpath (browser can show that, e.g. right-click) starting at body and accept that any page layout change is going to breask your specs and they will need to be fixed. However until the page does change it will work.