Sign in to follow this  
Followers 0
pchakraborty

Getting coordinates of a button

5 posts in this topic

#1 ·  Posted (edited)

Hi

I am new to AutoIt. I am trying to get the coordinates of a button in a page. I am not able to do so. I tried by hard coding the mouse cordinates displayed in the AutoIt Window Info tool and it works. By the same coordinates don't work in some other machine. Please suggest some way to find the coordinates of the button dynamically, irrespective of machine I am executing my script, so that I could go to that coordinate and mouse click on that button.

Please help.

I am currently trying this code as below

WinActivate("Online Community - Windows Internet Explorer");

ControlClick("Online Community - Windows Internet Explorer", "", "Browse...", "left", 1);

WinWait("Choose File to Upload");

WinActivate("Choose File to Upload");

ControlSetText("Choose File to Upload", "", "[CLASS:Edit; INSTANCE:1]", "D:\Image1.jpg");

ControlClick("Choose File to Upload", "", "[CLASS:Button; INSTANCE:2]");

Thanks

Parikshit

Edited by pchakraborty

Share this post


Link to post
Share on other sites



pchakraborty,

Welcome to the AutoIt forum. :P

ControlGetPos should get you the position of the button, but as you already have sufficient ID information to try and use ControlClick I am somewhat at a loss to see why you need it. :x

Furthermore, if the ID information is not good enough to let you use ControlClick, then I would be very surprised if it was sufficient to get the position either! :shifty:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi

Thanks for the reply. But let me explain you clearly what I am facing.

I have one webpage and there is a Browse button in that page to select and upload file. Initially i tried with ControlClick as below

ControlClick("Online Community Windows Internet Explorer", "", "&fileData", "left", 1)

But the script is not able to proceed further. Rather, it is getting stuck in that statement and not working for me.

Then I tried with MouseClick, but for that I had to provide both X&Y coordinates. I got those coordinates through Info tool and it was working fine for the moment. Next moment the coordinates got changed and my script failed.

For getting the coordinates of the Browse button dynamically, I tried ControlGetPos also, but its giving me the coordinates of the page i am in, rather than the coordinates of the button. The info tool always gives me the ControlID for the Browse button as 0.

I am currently trying the code as below:

dim $pos;

WinActivate("Online Community Windows Internet Explorer");

$pos = ControlGetPos("Online Community Windows Internet Explorer", "", "&fileData");

MouseClick("left", $pos[0], $pos[1], 2)

WinWait("Choose File to Upload");

WinActivate("Choose File to Upload");

Sleep(1000);

ControlSetText("Choose File to Upload", "", "[CLASS:Edit; INSTANCE:1]", "D:\Pic1.jpg");

Sleep(1000);

ControlClick("Choose File to Upload", "", "[CLASS:Button; INSTANCE:2]");

Sleep(1000);

fileData is the name of the button.

But unfortunately, that is also not working. Really no idea how to proceed and what else to try. Please help

Thanks

pchakraborty

Edited by pchakraborty

Share this post


Link to post
Share on other sites

pchakraborty,

Apologies, I did not notice you were trying to interact with a web page - although the clue was there: "Online Community Windows Internet Explorer".

Look at the IE management UDF in the Help file - there are lots of functions there to help you interact with web pages (if you use IE of course). They act directly on the page, so you will not have the coordinate problem on differenet machines when you use them. :x

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Hi

Thanks for your reply. But I need my script to work in different browsers like firefox,chrome, safari etc and not only in IE. Could you please suggest how should I proceed and solve this problem?

Thanks

pchakraborty

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0