0

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.

dynamic number

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):

enter image description here

Can I use the location to copy the random numbers with CSS or maybe some kind of 0-9/* functions or any other suggestions?

Update: TushaGT:

//table/td/span/b - it picks up 2 elements: enter image description here

And I need only the dynamic number, I got it to copy both through getText but 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
  • Do you have any control over the markup, so that you could put something useful on there? Is the structure stable such that you could use an XPath that doesn't specify the content? – jonrsharpe May 3 at 16:36
  • Hello thanks for your comment, No I don't have any control. – Alex Markovich May 3 at 18:00
1

You can use

//table/td/span/b

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.
0

If I understand correctly, you are looking to capture the number within the b tag (which is dynamic). You could try using the following XPath:

//table//td/span/b

Once you capture the above element via Selenium, then a getText() method should give you the answer. Of course, for the XPath to work, as @jonrsharpe mentions, the structure is assumed to be stable.

  • Hey TusharGT this: //table//td/span/b locates both elements: – Alex Markovich May 6 at 15:35
  • Looks like the span tag above the one of interest has the first text you are capturing. I missed it since it was not expanded :) You can use indexing. For example, (//table//td/span/b)[2] – TusharGT May 6 at 17:53
  • For a better understanding of the XPath, you can refer to this stackoverflow.com/questions/3674569/… – TusharGT May 6 at 17:55
0

I can see the class attribute for the 'td' tag, assuming that it is unique, can you try using the below

"//td[@class='yiv4414392908mobilePad']/span[2]/b"
  • 1
    This attribute "yiv4414392908mobilePad" changes too. – Alex Markovich May 6 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.