How to get the object if the text is contained in a <p></p> but there is <strong> </strong> and <br>inside the <p> </p>

Hi

I want to verify if the text contained inside this paragraph is correct but I cannot get the text and make it into object. I used Verify Element Text but so far, I was just able to use it in the text inside the <strong> <strong> tag. I want to check the other text inside the <p> </p> too but can’t do so because there is a <strong> </strong> tag and a <br> inside. Here’s a snippet of what I was referring to.

WebUI.getText() will retrieve the content of the innerText property of the element.

I would expect that verifyText would do the same - retrieve the innerText then do the comparison. @ThanhTo - is there a discrepancy here?

@mark.jabay you could use getText and do the comparison yourself.

I used chroPath to capture the element and make it into object. I stored the captured xpath into a label_companyPolicy_1 object. After doing so, I used the Get Text keyword but in the Script View, I stored the value of the Get Text into a variable name called companyPolicy in order for me to use this variable in the actualObject Field. However, after doing the steps above, still I wasn’t able to verify if the text inside the paragraph is equivalent to my expectedObject.

Sorry, I can’t figure out what’s going wrong there. I don’t use Test Objects - they make this kind of thing unnecessarily complicated. Maybe someone else can help…

Oh. Okay. But you mentioned to use Get Text. Can I ask how would you do it on your end using the Get Text keyword? I guess we need to use Test Objects because that is going be the basis of what we are expecting? Correct me if I’m wrong.

@Russ_Thomas

Both getText and verifyElementText use element.getText(), so there should be no discrepancies.

@mark.jabay
Can you place getText from the element, print it out, and then use that text in verifyElementText to see if the result from getText is as expected and wether the result is usable in verifyElementText ? Something like this

String text = WebUI.getText(findTestObject('your Element'));
println text;
WebUI.verifyElementText(findTestObject('your element'), text);
1 Like

I tried it but here’s the result. It appears that it didn’t get the text from the object captured.

@mark.jabay

Could it be a timing problem ? If you put a delay for 3,4 seconds before getText does it still not work ?

Oh wait. on the getText line, it was able to capture the object and the entire text, but when I tried to print it, it didn’t show up.

Please provide the full script, sounds like something maybe weird.

As mentioned in the post above, there is a <br> after the words Work Week <br>
A Work Week is composed of five (5) working days and two (2) Rest Days, except for Holidays.

Here’s the script:

String companyPolicy = WebUI.getText(findTestObject('View Shift/label_companyPolicy_1'), FailureHandling.STOP_ON_FAILURE)

System.out.println(companyPolicy)

WebUI.verifyElementText('View Shift/label_companyPolicy_1', 'Work Week A Work Week is composed of five (5) working days and two (2) Rest Days, except for Holidays.')

Try:

String companyPolicy = WebUI.getText(findTestObject('View Shift/label_companyPolicy_1'), FailureHandling.STOP_ON_FAILURE)

System.out.println(companyPolicy)

WebUI.verifyElementText('View Shift/label_companyPolicy_1', companyPolicy)

Also, view the result in Console Tab, in Log Viewer the value of the variable may not be displayed.

I tried the script that you posted and still it failed. Here’s the result in Console tab.

Okay, guys. thank you so much for the help. I was able to find a solution. I just used \n instead <br> and it worked so well. Again, thank you very much for the help.

2 Likes

Hi @mark.jabay
where did you put \n ?

Solved, I try put on script and it worked so well, thanks for the clue @mark.jabay