Wake Gregg Posted January 16 Report Share Posted January 16 Hello, I am trying to have a macro press a website button that shifts horizontally based on the width of the field before it. Mouse control doesn't work. Is there a way to have the macro select the button by name to activate it? What is the best way to handle this? Wake Quote Link to comment Share on other sites More sharing options...
Cory Posted January 16 Report Share Posted January 16 MEP isn't the greatest at web automation. I typically use other tools. But when I do, I avoid using the mouse. Generally I get to any page element by tabbing thought them. So count how many tabs to the button then text type the Enter button. Quote Link to comment Share on other sites More sharing options...
rberq Posted January 17 Report Share Posted January 17 Often there is text in a button that you can search for, that gives focus to the button. This code finds the Log Out button on a particular page and "presses" the button by typing ENTER. Text Type (Simulate Keystrokes): <CTRLD>f<CTRLU>log out<ESC> Delay: 250 milliseconds Text Type (Simulate Keystrokes): <ENTER> Sometimes you can search for text that reliably precedes or follows the button, then tab forward or backwards to the button similar to what Cory described. Quote Link to comment Share on other sites More sharing options...
Cory Posted January 17 Report Share Posted January 17 That's a good point rberg. I was considering mentioning that. This is useful if the number of elements before the desired element varies. Quote Link to comment Share on other sites More sharing options...
acantor Posted January 17 Report Share Posted January 17 rberq's two methods are the main techniques I use. Here's a script for a banking application that searches for a fly-out menu, opens the menu, and searches for an item that appears in the fly-out menu: // Automate the two steps to Transfer Funds Text Type (Simulate Keystrokes): <ESC> // Try to cancel a process that is already started Text Type (Simulate Keystrokes): <CONTROL>f // First, search for unique text in "the Pay and Transfer" link... Delay: 20 milliseconds Text Type (Simulate Keystrokes): Trans // Pay and Transfer Text Type (Simulate Keystrokes): <ESC> Delay: 20 milliseconds Text Type (Simulate Keystrokes): <ENTER> Delay: 1000 milliseconds // Need at least half a second for the fly-out menu to unfurl Text Type (Simulate Keystrokes): <CONTROL>f // Second, search for unique text in the "Transfer Funds" link... Delay: 20 milliseconds Text Type (Simulate Keystrokes): er fu // Transf_ER FU_nds Text Type (Simulate Keystrokes): <ESC> Delay: 20 milliseconds Text Type (Simulate Keystrokes): <ENTER> <COMMENT Value="Automate the two steps to Transfer Funds"/> <TEXT TYPE Action="0" Text="<ESC>" _COMMENT="Try to cancel a process that is already started"/> <COMMENT/> <TEXT TYPE Action="0" Text="<CONTROL>f" _COMMENT="First, search for unique text in \"the Pay and Transfer\" link..."/> <DELAY Flags="\x02" Time="20"/> <TEXT TYPE Action="0" Text="Trans" _COMMENT="Pay and Transfer"/> <TEXT TYPE Action="0" Text="<ESC>"/> <DELAY Flags="\x02" Time="20"/> <TEXT TYPE Action="0" Text="<ENTER>"/> <DELAY Flags="\x02" Time="1000" _COMMENT="Need at least half a second for the fly-out menu to unfurl"/> <COMMENT/> <TEXT TYPE Action="0" Text="<CONTROL>f" _COMMENT="Second, search for unique text in the \"Transfer Funds\" link..."/> <DELAY Flags="\x02" Time="20"/> <TEXT TYPE Action="0" Text="er fu" _COMMENT="Transf_ER FU_nds"/> <TEXT TYPE Action="0" Text="<ESC>"/> <DELAY Flags="\x02" Time="20"/> <TEXT TYPE Action="0" Text="<ENTER>"/> Another technique, much more complicated, is to search for a pixel colour under the mouse cursor, along a path, or both. This demonstration script, when run in the Macro Express Script Editor window, locates the "Activations" tab by its colour by searching diagonally, south-east, from position (10,10) relative to the window. Because the script is moving in intervals of the square root of 2 (less than two pixels at a timeI, it's very slow. But in "real" scripts, I check more aggressively. Instead of moving (1,1) pixels at a time, I might move (10,10) or even (100,100) pixels. Mouse Move: 10, 10 Relative to Current Window Variable Set Integer %WinWidth%: Set to the Current Window's Width Variable Set Integer %WinHeight%: Set to the Current Window's Height Extended Math %WinWidthSquared%=%WinWidth%^2 Extended Math %WinHeightSquared%=%WinHeight%^2 Variable Modify Integer: %WinDiagonalSquared% = %WinWidthSquared% + %WinHeightSquared% Extended Math %WinDiagonal%=%WinDiagonalSquared%^.5 Text Box Display: Values Variable Set Integer %Count% to 1 Repeat Until %Count% Is Greater Than or Equal To "%WinDiagonal%" Mouse Move: 1, 1 Relative to Last Position Delay: 10 milliseconds Get Pixel Color from Beneath the Mouse into %PixelColour% If Variable %PixelColour% Equals "16777215" Text Box Display: GOT IT! Macro Stop End If Variable Modify Integer %Count%: Increment End Repeat <MOUSE MOVE Option="\x02" X="10" Y="10" _PROMPT="0x000A"/> <COMMENT/> <VARIABLE SET INTEGER Option="\x0A" Destination="%WinWidth%"/> <VARIABLE SET INTEGER Option="\x0B" Destination="%WinHeight%"/> <COMMENT/> <EXTENDED MATH Option="\x07" Destination="%WinWidthSquared%" Value1="%WinWidth%" Value2="2"/> <EXTENDED MATH Option="\x07" Destination="%WinHeightSquared%" Value1="%WinHeight%" Value2="2"/> <COMMENT/> <VARIABLE MODIFY INTEGER Option="\x00" Destination="%WinDiagonalSquared%" Value1="%WinWidthSquared%" Value2="%WinHeightSquared%"/> <EXTENDED MATH Option="\x07" Destination="%WinDiagonal%" Value1="%WinDiagonalSquared%" Value2=".5"/> <TEXT BOX DISPLAY Title="Values" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang4105{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 w \\f1 %Win\\f0 Width\\f1 %\r\n\\par \\f0 h \\f1 %Win\\f0 Height\\f1 %\r\n\\par \\f0 w^2 \\f1 %Win\\f0 Width\\f1 Squared%\r\n\\par \\f0 h^2 \\f1 %Win\\f0 Height\\f1 Squared%\r\n\\par \\f0 d^2 \\f1 %WinDiagonalSquared%\r\n\\par \\f0 d \\f1 %WinDiagonal%\r\n\\par \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0" _ENABLED="FALSE"/> <COMMENT/> <VARIABLE SET INTEGER Option="\x00" Destination="%Count%" Value="1"/> <REPEAT UNTIL Variable="%Count%" Condition="\x04" Value="%WinDiagonal%"/> <MOUSE MOVE Option="\x03" X="1" Y="1" _PROMPT="0x000A"/> <DELAY Flags="\x02" Time="10"/> <GET PIXEL COLOR Option="\x00" Rel_To_Screen="TRUE" Destination="%PixelColour%"/> <IF VARIABLE Variable="%PixelColour%" Condition="\x00" Value="16777215" IgnoreCase="FALSE"/> <TEXT BOX DISPLAY Title="GOT IT!" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang4105{\\fonttbl{\\f0\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/> <MACRO STOP/> <END IF/> <VARIABLE MODIFY INTEGER Option="\x07" Destination="%Count%"/> <END REPEAT/> Quote Link to comment Share on other sites More sharing options...
Cartwheels Posted February 8 Report Share Posted February 8 Lately, to navigate webpages I have been using surfingkeys. There is also Vimium C which is similar. It is an extension for Chrome browsers and maybe others too. The extension is for surfing the web without the mouse using mostly the keyboard. One feature is when you press "f" it marks all the links visible with a letter or letters. Then you can press that letter or letters on the keyboard and just like that you will have clicked on the link. So far for me, I like it and it seems to work pretty well with Macro Express. Edit- I should have mentioned that not only does it do links but input fields or boxes as well. One con about it, the letters aren't attached to the page. You have to scroll if needed first then press "f". The amount of scroll would have to be the same each time so you end up with the same letter for the link each time. It only assigns letters to the visible links, the links further down the page aren't assigned a letter. So that would be the reason to scroll down the page first . Quote Link to comment Share on other sites More sharing options...
Cory Posted February 8 Report Share Posted February 8 That's interesting. I'll have to check that out. Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.