Jump to content

Getting coordinates of a button


Recommended Posts

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
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • 13 years later...
26 minutes ago, Santhoshi_ch said:

Hi @pchakraborty Did you get any solution for this? Because I am having the same issue now.

Since the user @pchakraborty has not been active in the forum for 13 years, you will probably not receive an answer from him. Therefore, it would be better to start a new thread.

Regarding your question: The following links should help you  :

https://www.autoitscript.com/wiki/WebDriver#FAQ

 

 

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...