[WebUI] Get Text


#1

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

#3

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


#4

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


#5

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



#6

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.


#7

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


#8

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.


#9

Done, here’s the link.


#10

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?


#11

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.