Determine if element exists quickly

I have a performance issue I need to address. I need to determine when an HTML tag becomes visible. Katalon informs me when it thinks the web page has completed loading but this is incorrect. There is additional data downloading that is taking place after Katalon detects a completed page load. The trigger for when the page is completely loaded is when an HTML tag is displayed called “”. This graph is not available whenKatalon detects a completed page load but is displayed when it is absolutely complete.

To get around this, I search for the associated tag. My code snippet is below. Unfortunately my code has a slow response. I was wondering if there was an efficient way to detect this element perhaps using jQuery of something else.

Any help would be appreciated.

Here is the information from the page itself:

	//Start attribute load timer
	StopWatch eventAttributeTime = new StopWatch()
	//Check for all attributes loaded
	s_sharingGroupGraphLoaded = 'n'
	while (s_sharingGroupGraphLoaded == 'n') {
		//We need to verify tr>td>span>svg
		//First find the tr entries
		WebDriver attrDriver = DriverFactory.getWebDriver()
		WebElement attrTable = attrDriver.findElement(By.xpath("//table/tbody"))
		List<WebElement> tr_entry_list = attrTable.findElements(By.tagName('tr'))
		int i_tr_entry_list_count = tr_entry_list.size()
		KeywordUtil.logInfo('Num of tr entries: ' + i_tr_entry_list_count)

		//Now find td entries associated with the Distribution entry
		for (int i_searchTrData = 0; i_searchTrData < i_tr_entry_list_count; i_searchTrData++) {
			List<WebElement> td_entry_list = tr_entry_list.get(i_searchTrData).findElements(By.tagName('td'))
			//Find the Distribution entry
			if (td_entry_list.get(0).getText() == 'Distribution') {
				List<WebElement> span_entry_list = td_entry_list.get(1).findElements(By.tagName('span'))
				int i_span_entry_list_count = span_entry_list.size()
				KeywordUtil.logInfo('Num of span entries: ' + i_span_entry_list_count)
				if (i_span_entry_list_count > 0) {
					List<WebElement> svg_entry_list = span_entry_list.get(0).findElements(By.tagName('svg'))
					int i_svg_entry_list_count = svg_entry_list.size()
					KeywordUtil.logInfo('Num of svg entries: ' + i_svg_entry_list_count)
					if (i_svg_entry_list_count > 0) {
						KeywordUtil.logInfo('Attribute load complete')
						s_sharingGroupGraphLoaded = 'y'
					} else {
						KeywordUtil.logInfo('Attribute not loaded yet')

	//Stop the attribute timer

I won’t tell you about WebUI visible/presence methods since you probably already tried them. And because you’re suggesting you might try jQuery, I’ll tell you what I do in similar situations.

I use a bunch of JavaScript to ensure the element in question is “visible to humans”. In fact, I do that for all elements I’m concerned about, certainly every element I intend my test code to interact with.

However, checking for visibility can be tricky, especially when the elements you’re concerned about are lazily loaded, like yours are. So first, you need to find out when the page is fully ready. If you are using jQuery, you might try adding…

If that doesn’t help, report back and we’ll look a bit deeper.

Russ_Thomas, being a relatively newcomer to Katalon, could you possibly show a code snippet? I mentioned jQuery above because I saw some references to it in other posts while searching for an answer to my problem. Thanks in advance.

such cannot be solved by a ‘code snippet’.
to stabilize your test-cases, first you have to bring more details and perhaps relevant people may take a look and guide further.
it is a ‘case-by-case’ issue

Like I said…

until you can be satisfied you have a fully loaded page taking into account all network-related issues, I won’t move to the next step.

In fact, I’m now even more concerned – as you’re a “relative newcomer” I’m wondering where that (extremely lengthy) code you posted came from (code that doesn’t do very much at all considering it’s bulk).

So true. If I posted it, you’d probably have a bunch more questions, the first being “where and how do I use that?”

Seriously, listen to what @bionel is saying, and do what I said you need to do first.


Your issue is a difficult one. We (guys in this forum) need much more information than you wrote above. We need to reproduce your issue on our machine. We need to have the target web page in action and do try-and-error on it just like you did.

Is the URL of your target web page a public one? If so, please share the URL to us.

If you can not share the real URL to us for some reason, you should provide us some alternative material for study, which must be publicly accessible via the Internet.

Your page seems to be using some software product for SVG Graph. Then I guess that the product would have some public web site for demonstration where anyone can see the software product in action. You might be able to write a test against the demo page and reproduce your problem. If you could manage that, share the entire code to us — we would be able to work on your issue together on the testbed provided.

Unless a sufficient testbed is provided, I do not think we can contribute to your issue.

I want to thank everyone for their comments and suggestions. I know it was hard based on the information I provided but I gave you all I could. This was an internal security application and had confidential data in it.

That being said, I did come up with a work around. I replaced all the code I have above with the following:

	//Start attribute load timer
	StopWatch eventAttributeTime = new StopWatch()
	attrGraphLoaded = 'n'
	while (attrGraphLoaded == 'n') {
		boolean item = driver.findElements(By.xpath("//*[name()='svg' and @width='50']"))
		if (item == true ) {
			attrGraphLoaded = 'y'
	//Stop the attribute timer

Katalon detects when the page header is loaded using “WebUI.waitForPageLoad()” and this code waits until the “” is visible by waiting for the svg block to be created. (The “@width=‘50’” was added to uniquely identify the svg block I was interested in. There are multiple blocks on this page.) I now have a more accurate load time value for my performance data.

It’s great if you found your solution, however, I read the above statement and it does not make sense to me. You are getting a List<WebElement> into a boolean. Interesting if nothing else.

That’s it. I simply keep looping until I see the svg element “display”. Using “driver.findElement()” did not work. If I got to this point in the test script and the element was not there, the script would error out at this line. Using “driver.findElements()” gets me past this point at the appropriate time. The boolean will keep me in the loop until that time.