Click() on button or image

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Click() on button or image

Post by omayer » Thu Aug 23, 2012 7:34 pm

what will be the alternative method for click() on button or image since sometime object.click() missed the click , I tried w/delay, and object.performclick() but seems like both are not stable . Thank you in Advance.
Tipu

regex
Posts: 48
Joined: Tue Aug 14, 2012 5:47 pm

Re: Click() on button or image

Post by regex » Thu Aug 23, 2012 8:27 pm

Code: Select all


 public void ImageLeftClick()
        {
		
		Ranorex.Imaging.FindOptions.Default.Similarity = 0.98;
		Rectangle fullscreen = new Rectangle(0, 0, 1920, 1080);
		Bitmap current = Ranorex.Imaging.CaptureDesktopImage(fullscreen);
		Bitmap bmp = Ranorex.Imaging.Load("C:\\Users\\NAME\\Desktop\\image.bmp");
		List<Ranorex.Imaging.Match> rtnList = Ranorex.Imaging.Find(current, bmp); //Captures Entire GuideDBS Screen to memory
		
		int x = rtnList[0].Location.X + (rtnList[0].Size.Width/2); //Finds x center point
		int y = rtnList[0].Location.Y + (rtnList[0].Size.Height/2); //Finds y center point
		Ranorex.Mouse.Click(x, y); 
		
		int i = 0;
        }
This will click the correct image if the image is loaded locally. Having trouble casting the local image to a bmp from the repository item. If anyone has recommendations on this please let me know.

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Click() on button or image

Post by Ciege » Thu Aug 23, 2012 10:12 pm

omayer wrote:what will be the alternative method for click() on button or image since sometime object.click() missed the click , I tried w/delay, and object.performclick() but seems like both are not stable . Thank you in Advance.
This does not sound right. I've never seen Ranorex miss a click, unless the item to be clicked is offscreen and for some reason Ranorex was unable to scroll the screen.

Is this a web AUT? Do you have the zoom set to something other than 100%?
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: Click() on button or image

Post by omayer » Fri Aug 24, 2012 3:23 pm

Ciege, You are correct, click got missed when objects were offscreen and unable to scoll even though i have ensurevisible(), focus(). I do run my test on multiple screen which is connected to laptop .
Yes this is web AUT. Zoom set to 100%.
Tipu

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Click() on button or image

Post by Ciege » Fri Aug 24, 2012 4:12 pm

In that case what I personally would do would be write my own Click method. Have this method take the element you want to click as a parameter. Have the method search for the element and check if it is visible or not. If it is visible, click it. If it is not visible, determine where it lives currently and have your own code scroll it into view. When the method is written, you can call it anytime you want to click something and be assured that it will work since you will be the one making sure it is visible.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: Click() on button or image

Post by omayer » Fri Aug 24, 2012 6:13 pm

How to know scroll up or down to get the view
Tipu

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Click() on button or image

Post by Ciege » Fri Aug 24, 2012 6:16 pm

Use the scrollbars... Use the keyboard...
How do people do it themselves? Mimic that with code...
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
IanF
Posts: 60
Joined: Thu May 24, 2012 12:37 am
Location: Brisbane, Australia
Contact:

Re: Click() on button or image

Post by IanF » Mon Aug 27, 2012 6:04 am

Playing with scrolling.

If you want to know how to do something try recording the action then have a look at the code.

Code: Select all

 public void Mouse_Up_Online_Search()
        {
            repo.Online_Search.Self.MoveTo("1254;506");
            Mouse.ButtonUp(System.Windows.Forms.MouseButtons.Left);
        }

        public void Mouse_Down_Online_Search()
        {
            repo.Online_Search.Self.MoveTo("1251;232");
            Mouse.ButtonDown(System.Windows.Forms.MouseButtons.Left);
        }

        public void Mouse_Wheel2()
        {
            Mouse.ScrollWheel(600);
        }

        public void Mouse_Wheel()
        {
            Mouse.ScrollWheel(-480);
        }
Ian Fraser

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Click() on button or image

Post by Ciege » Mon Aug 27, 2012 7:44 pm

IanF wrote:If you want to know how to do something try recording the action then have a look at the code.
Thanks for this, and I wholeheartedly agree! The record/playback functionality can be of great use to quickly get an outline for your own code to do what needs to be done. It is a great way of learning how to code your own scripts. Just don't rely on it to do everything (like your error checking, etc)... Use it as another tool in your toolbox to get the job done...
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...