How to improve WebElement locator when testing

Sorry for my poor English and low knowledge of Katalon Studio.

I’m newbie for Katalon Studio product, previously little experience web automation with Selenium IDE.

I’m just finished my first record and play on my web application with Katalon Studio (not Enterprise Ed.). Then I ran my test case and found some elements spent about 30.268 sec prior moving to next. I did change all xpath and css in Object Repository for that elements but still shown slowness.

when comparing with Selenium IDE, record and play. Same element spent only 4 sec to detect and overall can complete within 1 minute 25 sec. That’s too long when comparing with another tool. Can any expert here guide me how to make it more faster

Selenium IDE - overall test complete within 1 minute 25 sec

Katalon Studio (Free Ed.) - overall test compelte within 5 minutes xxxx seconds

please guide me. thank you

2 Likes

we can not compare between selenium and Katalon , but execution time is totally depend on internet speed and other services.
Always try to use fixed ID attribute if available.In case the ID is dynamic (changed in every page load), should try to use other properties and below tips.
Depending on your system under test, try to use attributes that rarely changes when SUT makes changes, for example: name, ID, text, etc.

2 Likes

@jirayu.s

Do you have “Smart Wait” is enabled?

You should turn “Default Smart Wait” Disabled.

Then try again. You may encounter a new Error. If got it, please report the error here.

1 Like

You can change “Default wait for element timeout (in seconds)” from 30 to more smaller value, say 10.

Then your script will run more quickly: quickly fail in 10 secs rather than waiting long for 30 secs.

1 Like

I noticed that your test case script tries clicking a <button> element without waiting for the page to completely load into browser. That’s wrong. You must make sure that the page has been loaded and the HTML button becomes clickable.

You might be puzzled. Let me explain a bit.

Please note that a browser works asynchronously.

Loading a HTML from the net takes a few seconds; It is this slow.

But your test case script runs very fast without waiting for the page to load into the browser.

After calling Navite To Url, in a few milliseconds, your code will call Click. At that timing, the HTML has not been loaded into browser. Therefore the target <button> was not there yet. Your Click command couldn’t find the target <button>. The Click command got lost what to do. The Click command just hangs for 30 seconds. Then timeout expired. Your test case finally ended after 30+secs with an error.

This is what happened to you.

You, as a WebUI tester, have to understand what’s going on in the invisible world inside browser.


Your code should be edited like

[current]

WebUI.openBrowser(...)
WebUI.navigateToUrl(...)
WebUI.click(findTestObject("button_Log in via Microsoft Aure"))

[should rather be]

WebUI.openBrowser(...)
WebUI.navigateToUrl(...)
WebUI.verifyElementPresent(findTestObject("button_Log in via Microsoft Aure"). 10)    // time out in 10 secs
WebUI.click(findTestObject("button_Log in via Microsoft Aure"))
1 Like

I guess, you used Katalon Record tool to generate your Test Case.

The Record tool did not automatically generate a statement to wait for the HTML is fully loaded into browser, to wait for the button element to be present and clickable before your code actually click the butoon.

In my opinion, this is a defect of the Recorder tool. The Recorder tool should have generated WebUI.verifyElementPresent() or WebUI.waitForElementClickable() after WebUI.navigateToUrl() before WebUI.click().

I have ever seen many newbies got caught in this small trap and posted questions in this forum.

I can remember, several years ago when I was a newbie to Katalon Studio, I encountered this very defect of the Record tool. That was my first surprise about KS. I was just like you, @jirayu.s

The code generated by these tools will get you started with WebUI testing automation quickly. That’s good. But unfortunately the tools are not very much polished. So, you need to be prepared to improve the generated test codes manually for yourself.

1 Like

@atul.rai much appreciate to your reply, noted that for all your advice. My web element ID is static, not dynamic. Thanks for your help and support.

1 Like

@kazurayam I didn’t make any change on project settings, guess that Smart Wait is set as its default (may be enable). I’ll check and change it per your advice. And I’ll report progress soon.

I didn’t make any change on Default wait for element timeout (in seconds). I’ll change per your advice and let’s test it again.

@kazurayam I understood your explanation clearly. I’ll add more command per your advice.

@kazurayam I use Katalon Studio in recording my test case. Much appreciate in sharing your experience with me. Thanks a lot.

@kazurayam You’re correct, its default smart wait was ‘Enabled’. Once I follow your advice, it proceed with no issue at all. thanks a lot

1 Like
  1. No need to use Wait if you use Open Browser to open a URL
    2.If you use Navigate to URL you should use Wait

Open Browser will work as Driver. get() in selenium by default it will wait until the page gets loaded without any wait

Navigate To URL will not wait for the page to get load

Don’t use Hard Wait use the Wait for Page load Keyword to wait for the page to load

1 Like

Thank you for your response.

I am curious about it: if “Navigate To URL” will wait for the page to get load or not.

Could you please provide some evidence (or supportive documentation of any kind) that “Navigate To URL” will not wait?

By the way, I found an article

This says:

Functionally, the navigate().to() method behaves exactly the same as the get() method. In fact, it’s just an alias for the get() method and simply loads the specified URL in the remote web browser. And because it’s just an alias for get() , it also won’t return until the web page is fully loaded.

This is just opposite to your understanding. I am wondering which is right.

I guess that we disregard some condition that affects how the “Navigate to” command behaves. Also we haven’t payed enough attention to the version of Selenium 2, 3, 4.

@duyluong
@Shin

Do you have any input?

1 Like