Forum Discussion

nastester's avatar
nastester
Regular Contributor
4 years ago

Clicking certain area of an object on different screen sizes

I am encountering an issue where an object is clickable (to bring up a menu) but only in the upper right hand corner of it.  I cannot seem to map just the clickable area so when I do a test, I need to include coordinates of the object so that the correct area is clicked, thus opening the menu for additional items to be clicked. 

This works fine for me but when run on a co-worker's computer the test fails because our screen sizes are different so the object is not clicked in the right location.

 

Is there a way around this? 

 

Thanks!

  • This was solved by ensuring the project setting "Use XPath and CSS selectors for web objects" is selected. When it was selected, the object within an object could be mapped and thus clicked 

  • Yes.  Click by the object name instead of coordinates.  You have just found out why coordinates are not particularly reliable.

     

     

    • nastester's avatar
      nastester
      Regular Contributor

      This does not work for this scenario. Only clicking the top right of the object opens the menu. And we have found that having coordinates causes the test to fail on other screens since positioning is not the same. 

      • Marsha_R's avatar
        Marsha_R
        Moderator
        Coordinates will always cause that issue.

        Show us the detailed object spy results from that button please.
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

     I need to include coordinates of the object so that the correct area is clicked

    Can you provide your code for this action?

     

    • nastester's avatar
      nastester
      Regular Contributor

      This particular test is keyword based but the underlying code is:

      page.panelDevicecardcontainer.panelDevicedatacontainer.Click(144, 11);  //works for me

       

      When my coworker records the click action, he of course gets different coordinates: 
      //page.panelDevicecardcontainer.panelDevicedatacontainer.Click(111,6);

       

      This doesn't work because the "object" to open the menu (see earlier screenshot) as the object seemingly needs to be clicked in top right only:
      //page.panelDevicecardcontainer.panelDevicedatacontainer.Click();

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        page.panelDevicecardcontainer.panelDevicedatacontainer.Click(144, 11);  //works for me

        You may try to click, say 10 pixels left from the right edge of control and 5 pixels down from its top to hit the clickable area. Usually this works when test code is executed on systems with different screen resolutions. E.g.:

        var pointX = page.panelDevicecardcontainer.panelDevicedatacontainer.Left + page.panelDevicecardcontainer.panelDevicedatacontainer.Width - 10;
        var pointY = page.panelDevicecardcontainer.panelDevicedatacontainer.Top -  5;
        page.panelDevicecardcontainer.panelDevicedatacontainer.Click(pointX, pointY);  // clicks 10 pixels left from the right control's edge and 5 pixels down from the top

         

  • nastester's avatar
    nastester
    Regular Contributor

    This was solved by ensuring the project setting "Use XPath and CSS selectors for web objects" is selected. When it was selected, the object within an object could be mapped and thus clicked