Clicking tab once the page loads through katalon command

I am stuck in automating this test case

  1. Launch the browser and open application URL (e.g. google.com)
  2. Once page loads, hit the tab key and verify that the first element in focus is ‘xx’ element

I have used WebUI.sendKeys(findTestObject(‘Object location’), Keys.chord(Keys.TAB)) many times with success. But here I cannot focus on the URL and hit tab

Please help

1 Like

kindly share the error trace or screenshot

Hi,

I suggest that you have:

  • waitForPageLoad() to make sure the page is loaded
  • you can try switchToWindow() to Switch focus to the browser window then sendKeys()
  • verify the focused element by getFocusedElement()
1 Like

What Object location can I put in SendKeys?

WebUI.sendKeys(findTestObject(‘Object location???’), Keys.chord(Keys.TAB))

No error as nothing is created. Need to know what to put in ‘Object Location’ for sendkeys

Hi,

I found this example:

'Press Ctrl+A to select all text in txt_Comment'
WebUI.sendKeys(findTestObject('txt_Comment'), Keys.chord(Keys.CONTROL, 'a'))

Replace txt_Comment with your xx element

I like @Elly_Tran’s idea of using “switchToWindowIndex(1)”, and then return to the original page, “switchToDefaultContent()”, but I was not able to find any information on the method, getFocusedElement(). Otherwise, I think this would be the easiest way to go about your concern.

Doing something a user would never do is decidedly not cool. And loading another page/window and then switching between them? Terrible idea. Even if you get this to “work”, what is it testing? What does the result even mean? Answer: It works as long as you do weird things no one would ever do.

@hemant.mishra.extern have you tried the robot api?

import java.awt.Robot

https://docs.oracle.com/javase/8/docs/api/java/awt/Robot.html

If you can’t get that to work, let me know.

1 Like

Thanks for your response. It worked with the method mentioned by Russ!

2 Likes

Russ, you are awesome! It worked with this. Now it looks so simple

Steps:
import java.awt.Robot

  1. loading website
  2. Robot robot = new Robot()
    robot.keyPress(KeyEvent.VK_TAB)
    robot.keyRelease(KeyEvent.VK_TAB)
    WebUI.delay(5)
  3. next steps…
4 Likes

@hemant.mishra.extern Glad you got it to work. And thanks for the praise. :clap:

2 Likes