Parse text of the element if text has <br> inside

Hi,
Could you please help me to parse a text of the element if the text has br element inside?
It is a timestamp. I need to analyze time without a date.

I did it by .substring, but I don’t like the idea to tie start index to the length of a string.
I need to know how to define indexOf(‘
’)

Thank you in advance for your help!

reportsTimeStampJobsite= WebUI.getText(findTestObject('Object Repository/Smoke Test Objects/M'), FailureHandling.CONTINUE_ON_FAILURE)
  println (reportsTimeStampJobsite)
reportsTimeStampJobsite_0 = reportsTimeStampJobsite.substring(reportsTimeStampJobsite.length() - 7, reportsTimeStampJobsite.length() - 3)
  println (reportsTimeStampJobsite_0)
  def String aJobsite = '0'+reportsTimeStampJobsite_0
  println (aJobsite)

2023-03-13 (2)

If you do a search for “indexOf” for Java, you will likely find pattern or Matcher, but I would suggest using “split” which breaks up a String based on the RegEx character used.

reportsTimeStampJobsite_time = reportsTimeStampJobsite.split(",")[1]

this gets the second part (lists start at zero) of your timestamp which would be the time. If needed, you can get the date by:

reportsTimeStampJobsite_date = reportsTimeStampJobsite.split(",")[0]
1 Like

Thank you for your answer.
I still have a problem with a timestamp because there is br element after comma that is the first after splitting. I need to remove this empty line to be able to calculate duration between two timestamps.

Thank you for your help!

Just trim() it away

Thank you for your answer.
trim() does not work here.
<br> element is not visible for web driver

No :joy::rofl::joy:

On the split() strings!

@mwarren04011990 Unfortunately I did not get your suggestion(

This is why knowing how to code should be prerequisite before taking on this line of work…

The question is open.
As a user of a low-code platform for automation I need a little bit more clarification from more experienced people to solve the problem.

Please RTFM and think about what you’re tryna do here…

You split() the String into date string, and time string, are interested in the time string but it has whitespace (i.e. newline) prefixing and postfixing it…

You need that part without the whitespace… What do you think trim() does? What part should that method be called on?

As a wannabe experienced user you should take some time to learn coding.
The issues you rise are not trivial.

It is the comunity or it is you getting paid at your company?

You are looking for already made solutions, caming every time with a new issue.
Is that fair?

1 Like

The code you posted is code – there’s nothing “low-code” about actual code.

Fact: There is no low-code solution to real-world coding problems (in automation or elsewhere).

It’s hard to respond to a person posting about issues with code that they later want to disown and claim ignorance due to adoption of dubious (and ill-defined) low-code automation solutions.

If you want to work with cope-paste patchwork code (seriously NOT a good idea), use StackOverflow.

Now, your problem.

.trim(), substring() and indexOf() (in JS) are all viable solutions. Which you use is entirely your choice. I would advise you read the voluminous amounts of information available to make your choice and figure out which is best for you.

Good luck.

Her question would probably be down voted to hell and back before she gets the answer she’s looking for…

possible solution to get a timestamp as hh:mm in a specified task:

reportsTimeStampJobsite= WebUI.getText(findTestObject('Object Repository/Smoke Test Objects/M'), FailureHandling.CONTINUE_ON_FAILURE)

reportsTimeStampJobsite_pureTime =  reportsTimeStampJobsite.split(",")[1].trim().substring(0, reportsTimeStampJobsite.length() - 3)