Continuing the discussion from How can I check if a form field exists?:
- Sometimes you need to open a web page URL, but then pause until a certain HTML element is loaded, that you want to use.
- The below macro does exactly that.
- The best way to determine the HTML Element and the required CSS Selector is to open the web page, and right-click on the target UI element, and select "inspect".
- You can use either Chrome or Safari to do this, but I recommend Chrome, even if ultimately you will be using Safari in your workflow.
- If you need help with this, post a new topic with the URL and a screen shot of the UI element you want to target.
MACRO: Pause Until Web Page Element Exists [Example]
~~~ VER: 1.0 2019-02-26 ~~~
Pause Until Web Page Element Exists [Example].kmmacros (10 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.
Pause Macro Until Web Page Element Exists
- Element defined by querySelector CSS
- KM 8.2+
- macOS 10.11.6 (El Capitan)
- KM 8 Requires Yosemite or later, so this macro will probably run on Yosemite, but I make no guarantees.
NOTICE: This macro/script is just an Example
- It has had very limited testing.
- You need to test further before using in a production environment.
- It does not have extensive error checking/handling.
- It may not be complete. It is provided as an example to show you one approach to solving a problem.
How To Use
- Make changes to Macro as stated in the "Macro Setup" below
- Trigger this macro.
- It will then open the web page and pause until the HTML element is found.
- The Pause Until (While Action) will auto-cancel if not found within one minute.
Carefully review the Release Notes and the Macro Actions
- Make sure you understand what the Macro will do.
- You are responsible for running the Macro, not me. ??
- Assign a Trigger to this maro..
- Move this macro to a Macro Group that is only Active when you need this Macro.
- ENABLE this Macro.
REVIEW/CHANGE THE FOLLOWING MACRO ACTIONS:
(all shown in the magenta color)
- Open URL
- Set CSS Selector
- If desired, change the TimeOut of the "Pause Until" While Action
- Any Action in magenta color is designed to be changed by end-user
ACTION COLOR CODES
- To facilitate the reading, customizing, and maintenance of this macro,
key Actions are colored as follows:
- GREEN -- Key Comments designed to highlight main sections of macro
- MAGENTA -- Actions designed to be customized by user
- YELLOW -- Primary Actions (usually the main purpose of the macro)
- ORANGE -- Actions that permanently destroy Variables or Clipboards,
OR IF/THEN and PAUSE Actions
USE AT YOUR OWN RISK
- While I have given this limited testing, and to the best of my knowledge will do no harm, I cannot guarantee it.
- If you have any doubts or questions:
- Ask first
- Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.