Store text/Get text and store in a variable

Is there any way to look at an element on a website, get the text that is inside of that element and store it as a variable.
I would then like to reference the variable in an if statement.

Eg.
selected element value on the webpage = correct value

text = WebUI.getText(findTestObject(‘selected element’))

if (text == ‘correct value’) {
WebUI.setText(findTestObject(‘report’), ‘True’)
} else {
WebUI.setText(findTestObject(‘report’), ‘False’)
}

At the moment when I run this the else statement runs and returns false.

Someone knows how to solve this? I am with the same problem, need save the text of a text field, I tried to use the command GetText but doesn’t work, don’t save the text in a variable, I used the command this way:
var_saida = WebUI.getText(findTestObject(‘Page_CreateEvent/input_title1’))

If you look closely at the description of ‘Get Text’ keyword: “Get the visible (i.e. not hidden by CSS) inner text of the web element, including sub-elements, without any leading or trailing white space.”

So I believe the displayed text from your object is not a visible inner text. You can see my example below: username’s field value is actually displayed by ‘value’ attribute of its

You should use ‘Get Attribute’ instead, like this:

text = WebUI.getAttribute(findTestObject('Page_CuraHomepage/btn_MakeAppointment'), 'value')

Screen Shot 2018-03-15 at 14.53.01.png

2 Likes

Vinh Nguyen said:

If you look closely at the description of ‘Get Text’ keyword: “Get the visible (i.e. not hidden by CSS) inner text of the web element, including sub-elements, without any leading or trailing white space.”

So I believe the displayed text from your object is not a visible inner text. You can see my example below: username’s field value is actually displayed by ‘value’ attribute of its

You should use ‘Get Attribute’ instead, like this:

text = WebUI.getAttribute(findTestObject('Page_CuraHomepage/btn_MakeAppointment'), 'value')

Thank You Vinh,
I understood and worked here, but I found a new problem, the value of the field is just inserted when the page is refreshed, so I have to send the form with some problem( like a required field not filled) and after the page refresh I can get the text in value tag, so this is a problem of how the application was developed right?
Is there any way around this beyond what I’ve done?

This type of request is going trendy, and the following feature may suits your needs. If you think it does, you may upvote it for Katalon guys to add it in a further release :