racfriedman Posted February 26, 2021 Report Share Posted February 26, 2021 I am trying to have a macro click a certain word on a webpage which then drops down a menu. I was able to originally do this by having the cursor move to a specified location...now I found out that the word is not always in the exact same coordinates. Is there a work around for this? Quote Link to comment Share on other sites More sharing options...
acantor Posted February 26, 2021 Report Share Posted February 26, 2021 Search for text at or near your target. Once found, cancel the search. Tab or Shift + Tab to your target. Press Alt + down arrow (or F4) to drop the list. The script might look something like this. (You'll need to add delays between some steps.) Text Type (Simulate Keystrokes): <ESC> // Cancel, just in case. Text Type (Simulate Keystrokes): <CONTROL>f // Initiate search Text Type (Simulate Keystrokes): Occupation: // Text to search for Text Type (Simulate Keystrokes): <ENTER> // Start searching Text Type (Simulate Keystrokes): <ESC> // Cancel the search Text Type (Simulate Keystrokes): <TAB> // Navigate to the target (if needed) Text Type (Simulate Keystrokes): <ALT><ARROW DOWN> // Drop the list. If this doesn't work, try F4 instead Quote Link to comment Share on other sites More sharing options...
Cory Posted February 26, 2021 Report Share Posted February 26, 2021 In general, you will be better off learning how to use the keyboard to do things in a web page and use TextType to automate. Each control, including links in a webpage should be a tab-stop. All my later macros before I started writing programs were all based on the number of tabs it takes to get to any control in a web page. I have written hundreds of macros to automate web pages and found the overall effort and lines of code about 10% of that trying to use the mouse. Mouse moves is the road less travelled. And, BTW, that means it's the one you don't want to take 🙂 List boxes you can tab to them then arrow down or start typing to highlight an item. Do yourself a favor and look up a list of keyboard shortcuts available for your browser and try to use them first. 2 Quote Link to comment Share on other sites More sharing options...
rberq Posted February 27, 2021 Report Share Posted February 27, 2021 This command sequence works for me in Firefox, on several web sites, to log off. The ESC keystroke is necessary. Easy to test by doing it manually before incorporating it in a macro. Text Type (Simulate Keystrokes): <CTRLD>f<CTRLU> Delay: 100 milliseconds Text Type (Simulate Keystrokes): log off Delay: 100 milliseconds Text Type (Simulate Keystrokes): <ESC> Delay: 100 milliseconds Text Type (Simulate Keystrokes): <ENTER> Quote Link to comment Share on other sites More sharing options...
acantor Posted February 27, 2021 Report Share Posted February 27, 2021 If the target is a hypertext link, there is related search in Firefox that ignores text that isn't part of a link. In Firefox, pressing single-quote starts "Quick Find" which searches only for text in links: Text Type (Simulate Keystrokes): ' Delay: 100 milliseconds Text Type (Simulate Keystrokes): log off Delay: 100 milliseconds Text Type (Simulate Keystrokes): <ESC> Delay: 100 milliseconds Text Type (Simulate Keystrokes): <ENTER> This is helpful when a target word appears several times, sometimes as part of a link, and sometimes not, and you're only interested in the links. Quote Link to comment Share on other sites More sharing options...
rberq Posted February 27, 2021 Report Share Posted February 27, 2021 30 minutes ago, acantor said: If the target is a hypertext link, there is related search in Firefox That's neat! Didn't know that! I just tried it out. There are a few places where that will let me clean up my navigation. Quote Link to comment Share on other sites More sharing options...
acantor Posted February 27, 2021 Report Share Posted February 27, 2021 "Quick Search" has a limitation. If a text box happens to have keyboard focus, pressing the single quote character inserts the character instead of initiating the command. I know two workarounds: 1. Use Ctrl + F, then deal with the need to search all text on the page. The advantage is that Ctrl + F works whether or not a text box is focused. 2. Identify a "neutral area" of the web page and click in it before initiating a Quick Search. A "neutral area" is my term for an area of the page that, when clicked, takes focus from wherever it is and puts it somewhere else... in this case, NOT in a text field. Sometimes, I search for a neutral area by hunting for a pixel colour or mouse cursor shape. Other times, I pick an x,y coordinate that seems to do the trick. Once I've identified a neutral area, the macro clicks it and then presses the single quote. A strategy I haven't tried recently is to reassign Quick Search to a Function key or to Ctrl + or Alt + combination. There may be add-ins that allow this, but I haven't found one yet. Quote Link to comment Share on other sites More sharing options...
rberq Posted February 27, 2021 Report Share Posted February 27, 2021 10 minutes ago, acantor said: "Quick Search" has a limitation. If a text box happens to have keyboard focus, pressing the single quote character inserts the character instead of initiating the command. That's the first thing I discovered when testing out Quick Search. But yes, your neutral area technique works. 13 minutes ago, acantor said: The advantage is that Ctrl + F works whether or not a text box is focused. The biggest problem I have had with either one is, if the words being searched for appear more than once on the page -- how to get the right one. Quote Link to comment Share on other sites More sharing options...
acantor Posted February 27, 2021 Report Share Posted February 27, 2021 2 hours ago, rberq said: The biggest problem I have had with either one is, if the words being searched for appear more than once on the page -- how to get the right one. These are exactly the kinds of situations when macros gets convoluted! Here is how I handle these situations. The basic technique is to navigate close to the target, and then either Tab or Shift + Tab, as many times as necessary, to zero in on the target. Let's say a webpage has two headers and several text boxes with the same names: About you Last name: [ ] First name: [ ] About your family Last name: [ ] First name: [ ] Last name: [ ] First name: [ ] etc. To navigate to the "First Name" field in the "About your family" section: Esc // Cancel, just in case Ctrl + F // Initiate find family // or "your family" or "about your family" Esc Tab Tab Despite the complexity of macros that zero-in on targets, I find they can be nearly 100% reliable. But the scripts almost always need to be tweaked, especially when figuring out delays between steps. Inserting two-second delays between each step might make the macro more bulletproof, but it's overkill; besides, I want macros to run as quickly as possible to reduce the chances of the unexpected event happening while a script is running, e.g., another window stealing focus. Programmatic access would be better, but even that's not a guarantee that everything will be right. I have MEP macros for Filezilla that capture and give focus to controls, so in theory the scripts should always work. But with each Filezilla update, the control information usually changes. So my MEP scripts need updating, too. Quote Link to comment Share on other sites More sharing options...
racfriedman Posted March 1, 2021 Author Report Share Posted March 1, 2021 Thank you everyone! I was able to figure it out 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.