Forum Discussion

ys_chee's avatar
ys_chee
Occasional Contributor
12 years ago
Solved

Clicking a button found on different coordinates

I apologise for asking a simple question, but I would like to know how do I click a button if the coordinates are different?



In the attached picture below, I want to click on Logout, but some of the buttons are found in different coordinates since the users are of different types. As such, certain buttons are missing if the user is of a lower rank, which meant they have Logout nearer to the left.



Thanks for reading.
  • You should look at the list of properties used to find Logout button in Name Mapping window. If these properties with their values does not uniquely identify the Logout button in all test cases then you should modify this list after finding such a properties.

7 Replies

  • If TestComplete recognized the Logout button as separate object then you should not worry about its coordinates - just call Click() for this object and TestComplete will click on it whereever it will be at the moment. Try to "catch" the button with Finder tool - if TestComplete will highlight it with red frame then everything should be fine :-)
  • ys_chee's avatar
    ys_chee
    Occasional Contributor
    I do not completely understand the solution that you are proposing, since I couldn't get it to work, so some elaboration would be appreciated.



    To elaborate on the problem I am facing, I am using Data Loop to loop the data, and users with different statuses would have a slightly different layout in the page. When the Logout button is found on a different location, the system wasn't able to detect it, from what I did with it. I attached two pictures to show what I meant.



    In the Click_OK picture, everything worked fine. However, in the Click_Not_OK picture, because the Logout button is found on a different spot, the system didn't find the Logout button and will not move on.



    Another thing: when I attempted to use Data Loop to search for the Logout link, there will be an error found in the Click_Error picture.



    So I ask again: what should I do to be able to click on the Logout button if it is found in different locations for each user?



    Thanks for reading.
  • sastowe's avatar
    sastowe
    Super Contributor
    Please show us the lines of code you are using to perform the different button clicks.
  • I misunderstood your question. It seems that you don't know how to find Logout button. There are many ways to find the needed object, one of them is using Page.NativeWebObject.Find method like this:

    var btn = your_web_page_object.NativeWebObject.Find("innerHTML", "Logout", "INPUT");

    See details here: http://support.smartbear.com/viewarticle/30881/

    The best way depends on how is your test organized at the moment. So as Stephanie said, it will be more productive if you will post your test code here.
  • ys_chee's avatar
    ys_chee
    Occasional Contributor
    Not sure if this is how the code is put, so if there is a better way of turning the commands into script, please tell.



    ================



    Sub Test1()

      'Opens the specified URL in a running instance of the specified browser.

      Call Browsers.Item(btFirefox).Navigate("http://localhost/peopleess/UserLogin.aspx")

      Call Project.Variables.DataLoop.Reset

      Dim RecordIdx

      RecordIdx = 1

      While RecordIdx < 2

        Call Project.Variables.DataLoop.Next

        RecordIdx = RecordIdx + 1

      WEnd

      RecordIdx = 2

      While RecordIdx <= 3

        'Clicks at point (42, 6) of the 'textboxTxtusername' object.

        Call Aliases.browser.pagePeopleess2.formForm1.table.cell.tableFormtable.cellCell1.textboxTxtusername.Click(42, 6)

        'Sets the text KeywordTests.Test1.Variables.DataLoop("UserID") in the 'textboxTxtusername' text editor.

        Call Aliases.browser.pagePeopleess2.formForm1.table.cell.tableFormtable.cellCell1.textboxTxtusername.SetText(Project.Variables.DataLoop.Value("UserID"))

        'Clicks at point (45, 16) of the 'passwordboxTxtpassword' object.

        Call Aliases.browser.pagePeopleess2.formForm1.table.cell.tableFormtable.cellCell11.passwordboxTxtpassword.Click(45, 16)

        'Sets the text KeywordTests.Test1.Variables.DataLoop("Password") in the 'passwordboxTxtpassword' text editor.

        Call Aliases.browser.pagePeopleess2.formForm1.table.cell.tableFormtable.cellCell11.passwordboxTxtpassword.SetText(Project.Variables.DataLoop.Value("Password"))

        'Clicks the 'submitbuttonBtnlogin' control.

        Call Aliases.browser.pagePeopleess2.formForm1.table.cell.tableFormtable.cellCellbutton.submitbuttonBtnlogin.ClickButton

        'Waits until the browser loads the page and is ready to accept user input.

        Call Aliases.browser.pagePeopleess1.Wait

        'Clicks at point (319, 253) of the 'panelSort1' object with the right mouse button.

        Call Aliases.browser.pagePeopleess1.formAspnetform.panel.panel.panelSort1.ClickR(319, 253)

        'Clicks the 'linkLogout' control.

        Call Aliases.browser.pagePeopleess1.formAspnetform.panelNavMenu.linkLogout.Click

        'Waits until the browser loads the page and is ready to accept user input.

        Call Aliases.browser.pagePeopleess2.Wait

        Call Project.Variables.DataLoop.Next

        RecordIdx = RecordIdx + 1

      WEnd

    End Sub
  • You should look at the list of properties used to find Logout button in Name Mapping window. If these properties with their values does not uniquely identify the Logout button in all test cases then you should modify this list after finding such a properties.
  • ys_chee's avatar
    ys_chee
    Occasional Contributor
    OK, I adjusted the name mapping to click the Logout button through its Pathname rather than its Name, and it works.



    Thanks for the tip!