Katalon Studio v5.8 - It's time for the all-new API testing experience
Yogesh Dhami
Katalon Apprentice
03/14/2018

Focus verification

When I load my web page the mouse cursor should display in 1st column of the 1st grid of page.So I have to verify that mouse cursor is coming or not..
How can I verify the by default focus is coming on expected field or not ?
please help me with that..!! 
Upvote
Quote

Comments

  • doan to uyen
    Katalon Apprentice
    08/10/2018
    When I load my web page the mouse cursor should display in 1st column of the 1st grid of page.So I have to verify that mouse cursor is coming or not..
    How can I verify the by default focus is coming on expected field or not ?
    please help me with that..!! 
    me too!!!
    Upvote
    Quote
  • kazurayam
    Katalon Evangelist
    08/10/2018
    edited August 10
    Try the following test case:

    import static com.kms.katalon.core.testobject.ConditionType.EQUALS
    import org.openqa.selenium.WebDriver
    import org.openqa.selenium.WebElement
    import com.kms.katalon.core.testobject.TestObject
    import com.kms.katalon.core.webui.driver.DriverFactory
    import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
    TestObject tObj = new TestObject()
    WebUI.openBrowser('')
    WebUI.navigateToUrl('https://katalon-demo-cura.herokuapp.com/')
    tObj.addProperty('xpath', EQUALS, "//a[@id = 'btn-make-appointment']")
    WebUI.click(tObj)
    tObj.addProperty('xpath', EQUALS, "//input[@id = 'txt-username']")
    WebUI.verifyElementPresent(tObj, 10)
    WebDriver driver = DriverFactory.getWebDriver()
    // find which element is currently focused by cursor
    WebElement focusedElement = driver.switchTo().activeElement()
    if (focusedElement.getTagName() == 'input') {
    WebUI.comment(">>> SUCCESS focused element is ${focusedElement.getTagName()}")
    } else {
    WebUI.comment(">>> FAILED focused element is ${focusedElement.getTagName()}")
    }
    WebUI.setText(tObj, 'John Doe')
    WebUI.delay(3)

    see also: 

    https://stackoverflow.com/questions/497094/how-do-i-find-out-which-dom-element-has-the-focus


    Upvote
    Quote
Sign In or Register to comment.