Need to press Tab right after a page loads in Katalon Studio and check which element gets focus? This community-inspired guide walks through opening the page, waiting for it to load, and sending Tab with Selenium Actions.
Hello, Katalon users and software testing enthusiasts! Today, we’re diving into a common challenge that many of you have encountered: navigating through a web page using the ‘Tab’ key. This blog post is inspired by a real-life scenario shared by a Katalon user on our community forum.
The Challenge
The user was trying to automate a test case where they needed to launch a browser, open an application URL (like google.com), and once the page loaded, press the Tab key to verify that the first element in focus was a specific element. They had used WebUI.sendKeys(findTestObject('Object location'), Keys.chord(Keys.TAB)) successfully in the past, but in this case they couldn't set focus on the page and press Tab.
The Solution
Let’s break down the solution into simple steps:
Step 1: Launch the Browser and Open the URL
First, we need to launch the browser and open the application URL. This can be done using the WebUI.openBrowser('') and WebUI.navigateToUrl('https://www.google.com') commands in Katalon Studio.
Step 2: Wait for the Page to Load
Next, we need to make sure the page has fully loaded before proceeding. We can use the WebUI.waitForPageLoad(5) command, which waits for the page to load within a specified timeout (in this case, 5 seconds).
Step 3: Set Focus and Press Tab
Now comes the tricky part. WebUI.sendKeys(findTestObject('Object location'), Keys.chord(Keys.TAB)) needs a test object to send keys to, so it doesn't help when you want to press Tab from the top of the page before any element has focus. Instead, send the key to the page itself with Selenium's Actions class, then check which element received focus:
import org.openqa.selenium.Keys
import org.openqa.selenium.WebDriver
import org.openqa.selenium.interactions.Actions
import com.kms.katalon.core.webui.driver.DriverFactory
WebUI.openBrowser('')
WebUI.navigateToUrl('https://www.google.com')
WebUI.waitForPageLoad(5)
// Press Tab on the page without targeting a specific element
WebDriver driver = DriverFactory.getWebDriver()
new Actions(driver).sendKeys(Keys.TAB).perform()
// Log the element that now has focus so you can verify it
String focused = WebUI.executeJavaScript('return document.activeElement.outerHTML', null)
WebUI.comment(focused)You can then compare the focused element with your expected test object, for example by checking its ID or name attribute.
Conclusion
Navigating through a web page using the ‘Tab’ key can be a bit tricky, but with the right commands and a bit of patience, it’s definitely achievable. Remember, the Katalon Community forum is a great resource for finding solutions to common challenges.
The information in this blog post is based on a real-life scenario shared by a user on our Katalon Community forum and is intended to inspire peer-to-peer discussion and collaboration. Please always test solutions thoroughly before implementing them in a production environment.
Feel free to continue the discussion on the Katalon forum.
Frequently asked questions
Use WebUI.sendKeys(findTestObject('Object location'), Keys.chord(Keys.TAB)).
Use WebUI.openBrowser('') and WebUI.navigateToUrl('http://google.com').
Use WebUI.waitForPageLoad(5) to wait up to 5 seconds for the page to load.
The scenario describes being unable to focus on the URL and hit Tab, meaning focus may not be set where Tab is intended to apply.
To press Tab after the page loads and verify the first focused element is a specific element.

Test everything. Ship with confidence.
From generating test cases to spotting failures, Katalon's AI works across your entire pipeline, automatically.





