Jump to content
Macro Express Forums

Click in a box on a web site without a mouse move


Recommended Posts

Everyone helped so much with my other issue.  I need help again.  I hope I can explain so you understand. I have a macro that needs to click into a box on a site to place a check in it.  I normally do a CTRL f to a word before or after the box, then tab or shift-tab to the box and click enter.  But this is not working.  My only option at this point is a mouse move.  But this page tends to change, so the mouse move may not work sometimes.  Do I have another option? I looked through samples, but my verbiage is iffy, so I may not know how Mac Exp lists the sample.

 

Link to comment
Share on other sites

Do you know the reason the search is failing?

 

One possibility is timing. You may need short delays between steps:

 

Text Type (Simulate Keystrokes): <CONTROL>f
Delay: 200 milliseconds
Text Type (Simulate Keystrokes): Address:
Delay: 200 milliseconds
Text Type (Simulate Keystrokes): <ENTER>

 

(200 ms delays are probably longer than needed!)

 

Another possibility is that the search must be cancelled before tabbing to the target. I use the Esc key to cancel web page searches:

 

Text Type (Simulate Keystrokes): <CONTROL>f
Delay: 200 milliseconds
Text Type (Simulate Keystrokes): Address:
Delay: 200 milliseconds
Text Type (Simulate Keystrokes): <ENTER>
Delay: 200 milliseconds
Text Type (Simulate Keystrokes): <ESC>

 

Another potential cause of failure is searching for an image of text rather than actual text. Macro Express has no OCR capability. One workaround is to search for text in a different area of the page, and then Tab (or Shift Tab) as many times as necessary to reach the target. (I've tabbed 20 or 30 times in extreme cases.)

 

Text Type (Simulate Keystrokes): <CONTROL>f
Delay: 200 milliseconds
Text Type (Simulate Keystrokes): Login // "Login" is the only "real" text on the page. All other labels are images of text. 
Delay: 200 milliseconds
Text Type (Simulate Keystrokes): <ENTER>
Delay: 200 milliseconds
Text Type (Simulate Keystrokes): <ESC>
Delay: 200 milliseconds
Text Type (Simulate Keystrokes): <TAB><TAB><TAB><TAB><TAB><TAB><TAB><TAB><TAB><TAB>
Delay: 200 milliseconds
Text Type (Simulate Keystrokes): <SPACE> // Check or uncheck the checkbox

 

There are other ways to zero-in on web page content, but these ways are more complicated: Hunting for pixel colours, tracking mouse pointer changes, and identifying areas of the screen that when clicked reset the tab order.

  • Thanks 1
Link to comment
Share on other sites

acantor said all what I could think of and more. If I could play with the site, I can usually find a way, but you can't grant us access to it I'm guessing. 

 

I love MEP but there are often times when it's incapable of doing simple web actions and what led me to professionally move on to other methods. To MEP the web page itself is one big control so it can't interact with the controls in the webpage. And even when one does get it to work, it's flying and shooting blind and takes tons of correctional and timing code. And in order not to fly blind. one needs to have some kind of extension or browser replacement to do this. 

The more popular are products like Postman oe Selenium, but it's pretty code heavy.  iMacros is a popular web plugin. 

My solution was to learn a programming language and create programs that send requests directly to the web server with no browser. It took awhile to learn it, but it's so much easier, more reliable, and faster I slapped myself in the forehead for not learning sooner. If you would like to learn more about a non-MEP solution, please feel free to contact me directly. I'm typically willing to give free consultations provided it not take longer than half an hour. 

Link to comment
Share on other sites

Oh! I did think of one thing. One can use a scripting language to send a POST request. I have written macros which use one simple script to work around a deficiency in MEP like sending a POST request. I just wanted to point out one doesn't have to go all-in to use direct requests. 

Link to comment
Share on other sites

One suggestion in addition to all the above --

 

Sometimes a web page, on the screen, is really more than one page.  (Or at least seems to be -- I'm not sure what is really happening under the covers.)  Before doing the Ctrl-f search, try clicking the mouse (once) somewhere in the vicinity of where you hope to find the word.  That will bring the right section of the screen into focus so the Ctrl-f will be operating on the proper area.  I generally have the macro click at the extreme left or right or top or bottom, so it won't accidentally hit a button and go off to never-never land.  You can easily test this on your particular web site by manually doing the mouse click and Ctrl-f. 

Link to comment
Share on other sites

I use a method similar to rberq's: the macro clicks a part of the screen that resets the tab order. Sometimes, the click forces Find to start searching a certain part of the window.

 

I call this region of a webpage its "neutral zone," but it's actually more of a "reset zone." Sometimes the zone is a band of colour along the top or left side of the window. But it can be elsewhere; and some pages don't have such a zone. In this example, I used trial and error to find the x coordinate, and calculated the y coordinate based on the height of the window.

 

// Click near the window's left boundary at the midpoint of its height...
 
Variable Set Integer %PixelsX% to 20 // x = 20 is a little to the right of the left edge of the window
Variable Set Integer %WindowHeight%: Set to the Current Window's Height
Variable Modify Integer: %PixelsY% = %WindowHeight% / 2 // y = the midpoint of the height of the window
 
Mouse Move: %PixelsX%, %PixelsY% Relative to Current Window
Mouse Left Click
 
Text Type (Simulate Keystrokes): <TAB><TAB><TAB>

 

These kinds of scripts tend to get complex, and they can be challenging to maintain. But on some badly designed webpages, it's the best method I've found... so far!

Link to comment
Share on other sites

On 7/16/2024 at 10:37 AM, acantor said:

Do you know the reason the search is failing?

 

One possibility is timing. You may need short delays between steps:

 

Text Type (Simulate Keystrokes): <CONTROL>f
Delay: 200 milliseconds
Text Type (Simulate Keystrokes): Address:
Delay: 200 milliseconds
Text Type (Simulate Keystrokes): <ENTER>

 

(200 ms delays are probably longer than needed!)

 

Another possibility is that the search must be cancelled before tabbing to the target. I use the Esc key to cancel web page searches:

 

Text Type (Simulate Keystrokes): <CONTROL>f
Delay: 200 milliseconds
Text Type (Simulate Keystrokes): Address:
Delay: 200 milliseconds
Text Type (Simulate Keystrokes): <ENTER>
Delay: 200 milliseconds
Text Type (Simulate Keystrokes): <ESC>

 

Another potential cause of failure is searching for an image of text rather than actual text. Macro Express has no OCR capability. One workaround is to search for text in a different area of the page, and then Tab (or Shift Tab) as many times as necessary to reach the target. (I've tabbed 20 or 30 times in extreme cases.)

 

Text Type (Simulate Keystrokes): <CONTROL>f
Delay: 200 milliseconds
Text Type (Simulate Keystrokes): Login // "Login" is the only "real" text on the page. All other labels are images of text. 
Delay: 200 milliseconds
Text Type (Simulate Keystrokes): <ENTER>
Delay: 200 milliseconds
Text Type (Simulate Keystrokes): <ESC>
Delay: 200 milliseconds
Text Type (Simulate Keystrokes): <TAB><TAB><TAB><TAB><TAB><TAB><TAB><TAB><TAB><TAB>
Delay: 200 milliseconds
Text Type (Simulate Keystrokes): <SPACE> // Check or uncheck the checkbox

 

There are other ways to zero-in on web page content, but these ways are more complicated: Hunting for pixel colours, tracking mouse pointer changes, and identifying areas of the screen that when clicked reset the tab order.

THANKS!!!! The 3rd option did it!!

Link to comment
Share on other sites

On 7/16/2024 at 2:42 PM, acantor said:

I use a method similar to rberq's: the macro clicks a part of the screen that resets the tab order. Sometimes, the click forces Find to start searching a certain part of the window.

 

I call this region of a webpage its "neutral zone," but it's actually more of a "reset zone." Sometimes the zone is a band of colour along the top or left side of the window. But it can be elsewhere; and some pages don't have such a zone. In this example, I used trial and error to find the x coordinate, and calculated the y coordinate based on the height of the window.

 

// Click near the window's left boundary at the midpoint of its height...
 
Variable Set Integer %PixelsX% to 20 // x = 20 is a little to the right of the left edge of the window
Variable Set Integer %WindowHeight%: Set to the Current Window's Height
Variable Modify Integer: %PixelsY% = %WindowHeight% / 2 // y = the midpoint of the height of the window
 
Mouse Move: %PixelsX%, %PixelsY% Relative to Current Window
Mouse Left Click
 
Text Type (Simulate Keystrokes): <TAB><TAB><TAB>

 

These kinds of scripts tend to get complex, and they can be challenging to maintain. But on some badly designed webpages, it's the best method I've found... so far!

YES! I remember doing this years ago.  But I don't remember how I did it.  Would I be able to paste your above info into a test macro to try?

 

Link to comment
Share on other sites

I don't think you can paste the above script code into the Script Editor. I deleted the original code, so I can't change it to a form that can be pasted into the Script Editor.

 

However, you can copy the code below, which I previously developed for the Google Search home page. I needed to click on a part of the white background to reset the tab order. This macro hunts for five white pixels in a row along a line next to the left border of the window.

 

The script starts checking pixels at coordinate (5, 50). To speed things up, the script checks along a vertical line, once every 10 pixels: (5, 60) then (5, 70) then (5, 80), and continues until a white pixel is found. (White = "16777215".)

 

When a white pixel is found, the script switches to checking every pixel instead of every tenth. It continues checking each pixel along the vertical line until five consecutive white ones have been found. If the macro finds, say, only two white pixels in a row, the script reverts to checking every ten pixels.

 

This version is a kluge for many reasons, including that it checks up to 1000 times. But 1000 was arbitrary. I know from experience that it works, but the value really should be calculated based on the size of the window, or perhaps the screen resolution. My script barely handles the situation when five white pixels in a row are NOT found after 1000 checks. This script needs refinement.

(As I hinted in an earlier message, reliable pixel hunting scripts can get very complex!)

 

But I hope this script gives you the basis to develop a pixel hunting script that meets your needs.

 

Variable Set Integer %PixelSearchIncrement% to 50
Variable Set Integer %WhiteCount% to 0
 
Variable Set Integer %MouseX% to 50
Variable Set Integer %MouseY% to 5
 
Repeat Start (Repeat 1000 times) // 1000 is arbitrary. It would be better to calculate a value based on the screen resolution or window dimensions.
  Get Pixel Color at (%MouseX%, %MouseY%) Relative to Current Window into %PixelColour%
  If Variable %PixelColour% Equals "16777215" // A white pixel was found!
    Variable Modify Integer %WhiteCount%: Increment
    Variable Set Integer %PixelSearchIncrement% to 1
    If Variable %WhiteCount% Is Greater Than or Equal To "5"
      Mouse Move: %MouseX%, %MouseY% Relative to Current Window
      Mouse Left Click
      Text Box Display: The white zone has been found!
      Macro Stop
    End If
  Else
    Variable Set Integer %PixelSearchIncrement% to 10
    Variable Set Integer %WhiteCount% to 0
  End If
  Variable Modify Integer: %MouseY% = %MouseY% + %PixelSearchIncrement%
End Repeat
 
Text Box Display: The white zone has NOT been found!

This version can be copied and pasted into the Script Editor:

<VARIABLE SET INTEGER Option="\x00" Destination="%PixelSearchIncrement%" Value="50"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%WhiteCount%" Value="0"/>
<COMMENT/>
<VARIABLE SET INTEGER Option="\x00" Destination="%MouseX%" Value="50"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%MouseY%" Value="5"/>
<COMMENT/>
<REPEAT START Start="1" Step="1" Count="1000" Save="FALSE" _COMMENT="1000 is arbitrary. It would be better to calculate a value based on the screen resolution or window dimensions."/>
<GET PIXEL COLOR Option="\x01" Rel_To_Screen="FALSE" X="%MouseX%" Y="%MouseY%" Destination="%PixelColour%"/>
<IF VARIABLE Variable="%PixelColour%" Condition="\x00" Value="16777215" IgnoreCase="FALSE" _COMMENT="A white pixel was found!"/>
<VARIABLE MODIFY INTEGER Option="\x07" Destination="%WhiteCount%"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%PixelSearchIncrement%" Value="1"/>
<IF VARIABLE Variable="%WhiteCount%" Condition="\x04" Value="5" IgnoreCase="FALSE"/>
<MOUSE MOVE Option="\x02" X="%MouseX%" Y="%MouseY%" _PROMPT="0x000A"/>
<MOUSE LEFT CLICK/>
<TEXT BOX DISPLAY Title="The white zone has been found!" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs14 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
<MACRO STOP/>
<END IF/>
<ELSE/>
<VARIABLE SET INTEGER Option="\x00" Destination="%PixelSearchIncrement%" Value="10"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%WhiteCount%" Value="0"/>
<END IF/>
<VARIABLE MODIFY INTEGER Option="\x00" Destination="%MouseY%" Value1="%MouseY%" Value2="%PixelSearchIncrement%"/>
<END REPEAT/>
<COMMENT/>
<TEXT BOX DISPLAY Title="The white zone has NOT been found!" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs14 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>

 

 

Quote

 

 

 

Link to comment
Share on other sites

That is above my pay grade. :) Not sure what else to do. i figured out all other issues except a left clcik in this area for a button.  Button is never in same spot and tab, shift tab, entr or space do not work

 

Link to comment
Share on other sites

Originally you said, “the mouse move may not work SOMETIMES.”  In your last post you said, “Button is NEVER in same spot.”  I’m not trying to be picky – which is correct??? 

 

I have a few web pages where the button moves but only to a few predictable spots.  So I just click on them all because clicking the wrong spot doesn’t hurt anything.  Or I check pixels at each of the few possible locations and click the one that matches.  This may not be applicable in your situation, but worth investigating. 

Link to comment
Share on other sites

What rberq says is important: If the position of the target is unpredictable, but the target appears within a predictable region, it's usually possible to find a solution.

 

Perhaps the target appears on a horizontal or vertical line. Or within a square or rectangular region. For example, if the field appears somewhere within the red rectangle...

 

image.thumb.png.2c80f6a274a2a3d34c15872a32754b61.png 

Here's a macro that clicks on every pixel along a 20 pixel long vertical line starting at (250, 250):

 

Mouse Move: 250, 250 Relative to Current Window // Start clicking here relative to the window
 
Variable Set Integer %HeightOfRegion% to 20
Variable Set Integer %y% to 1
 
Repeat Start (Repeat %HeightOfRegion% times)
  Mouse Move: 0, %y% Relative to Last Position
  Mouse Left Click
  Variable Modify Integer: %y% = %y% + 1
  Delay: 50 milliseconds // Slow down the macro...
End Repeat

 

 

image.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...