[WebUI] Get Text


This is a companion discussion topic for the original entry at https://docs.katalon.com/katalon-studio/docs/webui-get-text.html

How to set the innerText of a non-input element?

Can you give an example of what you mean? You could try importing

import org.openqa.selenium.Keys as Keys

and sending the desired text as key actions

WebUI.sendKeys(findTestObject(‘Your_Object_Goes_Here’), Keys.chord(Keys.ARROW_RIGHT))

Hi, can you help me why i can’t get text that input text?


You are not targeting the correct element. I typically bring up Object spy and capture as much of an element as possible. Notice that when you hover over elements, sometimes the red border shifts on just the text, the entire field, etc. Figure out how you need to target it then go from there. Technically, the element you targeted is there, its just empty.

I’ve come across an issue where WebUI.getText is not able to trim the trailing space in actual text.

The actual text rendered in webpage HTML has &nbsp at the end. This is causing the trailing space. I thought WebUI.getText will take care of it but it didn’t work.

Example:
Actual Text in webpage HTML: sample text 1&nbsp
Actual Text grabbed by WebUI.getText: sample text 1
Expected Text in Test Case: sample text 1

They said it removes whitespace in which case that’s a bug. Please make out a bug report, mention it should remove all whitespace including HTML entities like     etc.

Done, here’s the link.

The default wait time is 30 seconds for this method.
How do we reduce the wait time?
I don’t want to wait for 30 sec during execution. Can we do something about it?

To find out to use “getText” or “getAttribute”, right click on the page and select Inspect. Right click near the element you want to check and select Inspect a second time (the first time should open the code window and the second time should jump right to the element by your cursor). If your code looks like: <p class=“form b” Mike Boy


then use getText on the element.
if you code looks like:
<input id=“panel1” name=“panel_1” value=“Mike Boy”…
then use getAttribute using the “value” as the attribute.

You can also use the Properties tab on the lower corner to find the contents of other attributes for the element under investigate.

Hello,
Can i have, some help ?
Im looking for display the value of this element : cdc123
I used this commande : WebUI.getText(findTestObject(‘Page_FAYATFred/Pointage/Page_FayatFRED/Pointage/Liste des rapport/Label_Profil_connecté’))
the result is : “”
The expected result : “cdc123”

==> do you have any idea ?

You need to assign the value to a variable
def result = WebUI.getText(findTestObject(‘Page_FAYATFred/Pointage/Page_FayatFRED/Pointage/Liste des rapport/Label_Profil_connecté’)

result should be whatever the text was

Also, ensure you have the correct element selectors in your object repository

Take a look at the HTML code and see if the Element, cdc123, has the text you want to see associated with a “value” attribute or not. If not, then the “getText” should work. However, I would guess that your text is associated with a “value” attribute, for which you need, getAttribute(TO, “value”).

You can combine the getAttribute with a verifyMatch to test your result:

WebUI.verifyMatch(WebUI.getAttribute(findTestObject(textarea_TestDoc.ImportDocDescription’),
‘value’), “The text you want to see”, false)

To see the HTML code, right click and select INSPECT (you may have to do it twice to move to your location with Chrome).

How will get the dynamic value the text should be: 1981.0 KB/sec


can you help me with this

hello need help for this one

How to identify numbers in pictures
like:
捕获4