Object not found

Hi

I met a strange issue, this is part of my code:
WebUI.waitForElementPresent(findTestObject(‘XenMobile - Console - Logon/input_name’), 10)
WebUI.delay(3)
WebUI.setText(findTestObject(‘XenMobile - Console - Logon/input_name’), username)

When I try to run it, waitForElementPresent can find the object while setText cannot, log:
04-09-2018 02:28:52 PM - [START] - Start action : waitForElementPresent
04-09-2018 02:28:52 PM - [INFO] - Finding Test Object with id ‘Object Repository/XenMobile - Console - Logon/input_name’
04-09-2018 02:28:52 PM - [INFO] - Checking object
04-09-2018 02:28:52 PM - [INFO] - Checking timeout
04-09-2018
02:28:52 PM - [INFO] - Finding web element with id: ‘Object
Repository/XenMobile - Console - Logon/input_name’ located by ‘By.xpath:
//input[@type = ‘text’ and @name = ‘name’ and @id = ‘name’]’ in ‘10’ second(s)
04-09-2018
02:28:52 PM - [INFO] - Found 1 web elements with id: ‘Object
Repository/XenMobile - Console - Logon/input_name’ located by ‘By.xpath:
//input[@type = ‘text’ and @name = ‘name’ and @id = ‘name’]’ in ‘10’ second(s)
04-09-2018 02:28:52 PM - [PASSED] - Object ‘Object Repository/XenMobile - Console - Logon/input_name’ is present
04-09-2018 02:28:52 PM - [END] - End action : waitForElementPresent
04-09-2018 02:28:52 PM - [START] - Start action : delay
04-09-2018 02:28:52 PM - [INFO] - Delaying browser in 3 second(s)
04-09-2018 02:28:55 PM - [PASSED] - Delayed 3 second(s)
04-09-2018 02:28:55 PM - [END] - End action : delay
04-09-2018 02:28:55 PM - [START] - Start action : setText
04-09-2018 02:28:55 PM - [INFO] - Finding Test Object with id ‘Object Repository/XenMobile - Console - Logon/input_name’
04-09-2018 02:28:55 PM - [INFO] - Checking object
04-09-2018 02:28:55 PM - [INFO] - Checking text
04-09-2018 02:28:55 PM - [INFO] - Checking timeout
04-09-2018 02:28:55 PM - [WARNING] - Timeout ‘0’ is invalid. Using default page load timeout: ‘0’
04-09-2018
02:28:55 PM - [INFO] - Finding web element with id: ‘Object
Repository/XenMobile - Console - Logon/input_name’ located by ‘By.xpath:
//input[@type = ‘text’ and @name = ‘name’ and @id = ‘name’]’ in ‘0’ second(s)
04-09-2018
02:28:55 PM - [FAILED] - Unable to set text ‘a’ of object ‘Object
Repository/XenMobile - Console - Logon/input_name’ (Root cause:
com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web
element with id: ‘Object Repository/XenMobile - Console -
Logon/input_name’ located by ‘By.xpath: //input[@type = ‘text’ and @name = ‘name’ and @id = ‘name’]’ not found)
04-09-2018 02:28:55 PM - [END] - End action : setText
04-09-2018
02:28:55 PM - [FAILED] - Test Cases/login FAILED because (of) Unable to
set text ‘a’ of object ‘Object Repository/XenMobile - Console -
Logon/input_name’ (Root cause:
com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web
element with id: ‘Object Repository/XenMobile - Console -
Logon/input_name’ located by ‘By.xpath: //input[@type = ‘text’ and @name = ‘name’ and @id = ‘name’]’ not found)
04-09-2018 02:28:55 PM - [START] - Start listener action : sampleAfterTestCase

Can anybody help to see what’s happening here?

PS: “Timeout ‘0’ is invalid.” what’s timeout 0 means here?

Hi Yuran,
First, I think you have issues with your xpath. Please double check it or try with different locators.
Furthermore, you must set a default to wait for element timeout from main menu: Project > Project Settings > Execution > Default. ( 30s instead 0s ).

Hi Alice,

Thanks, I set the timeout to 10S, and it works.

But it still confuse me that, I call waitForElementPresent first and it pass which means the object is already there then I call setText, I supposed I don’t have to wait for the element so I set the timeout value to 0.

It seems that, once I set the value to 0, the object will always not be found even it’s already there.

It doesn’t make sense to me…

Hi Yuran

It’s usually better to test for (or wait for) an object to be “Visible” (as opposed to “Present”). To explain why that is the case…

When a browser downloads an HTML page from a server, one of the first things it does is to build the DOM (the document object model) which is like a “tree representation” of the HTML in the page.

When you test for “Present”, all you are doing is asking the browser “is this thing in the DOM?” When the browser answers “yes” to that question, you might expect the object is “ready”… “ready to work with”…

The problem with that is, there is still a ton of stuff that the browser needs to do. For one, it still has to create the DOM elements and place them on the page in their correct positions (according to standard HTML layout rules) and then make adjustments for CSS rules…

After that, it needs to run any JavaScript which might also move things around and (worse?) create NEW elements which need to be added to the DOM which moves other things around and makes even more adjustments to the layout.

Can you see the problem?

“Present” doesn’t really mean “yes it’s present and it’s ready to use”.

“Visible” implies it’s in the DOM and it’s visible on the page…, that’s a lot “closer” to being ready to use and therefore more reliable.

I hope this gave you some insight as to why you’re seeing the issues you’re seeing.

Russ

3 Likes

Hi Russ

It helps a lot. Thank you very much!