Jump to content

Get screen width in watir


mahecu
 Share

Recommended Posts

Hi,

I have a watir script where I am using an autoit control to get the mouse to click on certain web page locations. I would like to know if there is a method for getting the screen width and height, to then supply the coordinates to the autoit control.

Mark

Link to comment
Share on other sites

Hello mahecu,

Would you mind sharing your WATiR script. You can PM me if you do not wish to "junk up" the forum with non-AuoIt code. I'm curious as to why you're needing AutoIt to handle control events on the web page. Is this just a workaround for a particularly nasty web element?

Zach...

Link to comment
Share on other sites

Hi Zach,

Thanks for your interest. I am using AutoIt as a workaround. I am writing watir scripts to test an access control system my company develops. The system is accessed through Internet explorer and has many uncommon elements which I cannot attach to. In the case of the screenshot below I need to be able to click on the red bars and drag the mouse downwards to set timezones. The code below shows the mouse coordinates I am currently using but these only work when the screen resolution is set to 1024 x 768. If I can get the screen width and height I can then base my coordinates on these values. For example, currently I have an x coordinate of 275 using the 1024 x 768 resolution but if this coordinate is used with a 1280 x 1024 resolution it will not click in the same place. If I can get the screen width I can set up a variable that calculates the correct coordinate for that screen position whatever the resolution is by multiplying the screen width by 275/1024.

a = WIN32OLE.new("AutoItX3.Control")

$ie.send_keys('{F11}') # set browser to fullscreen mode to prevent toolbars from skewing coordinates

a.mouseclickdrag("left",275,195,275,479,0) # set timezone for sunday

a.mouseup

a.mouseclickdrag("left",325,195,325,479,0) # set timezone for monday

a.mouseup

a.mouseclickdrag("left",375,195,375,479,0) # set timezone for tuesday

a.mouseup

a.mouseclickdrag("left",425,195,425,479,0) # set timezone for wednesday

a.mouseup

a.mouseclickdrag("left",475,195,475,479,0) # set timezone for thursday

a.mouseup

a.mouseclickdrag("left",525,195,525,479,0) # set timezone for friday

a.mouseup

post-28406-1197622414_thumb.jpg

Thanks,

Mark

Hello mahecu,

Would you mind sharing your WATiR script. You can PM me if you do not wish to "junk up" the forum with non-AuoIt code. I'm curious as to why you're needing AutoIt to handle control events on the web page. Is this just a workaround for a particularly nasty web element?

Zach...

Link to comment
Share on other sites

a = WIN32OLE.new("AutoItX3.Control")
width = a.WinGetPosWidth( ie.url, "")
height = a.WinGetPosHeight(ie.url, "")

I'm not sure if I'm accessing the URL property correctly but I think the idea comes across.

Zach...

Edited by zfisherdrums
Link to comment
Share on other sites

Hi Zach,

Thanks for your help, really appreciate it. At the moment I keep getting width and height values of 1 but I think you have put me on the right path to my solution.

Cheers,

Mark

a = WIN32OLE.new("AutoItX3.Control")
width = a.WinGetPosWidth( ie.url, "")
height = a.WinGetPosHeight(ie.url, "")

I'm not sure if I'm accessing the URL property correctly but I think the idea comes across.

Zach...

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...