MACRO: [WEB] Click on Link Using XPath [Example]
~~~ VER: 2.0 2016-10-12 ~~~
- See YouTube Video showing how to get XPath, and then demo of this macro.
See the below post for an example.
- Click on the Hyperlink Identified by the XPath
- Requires either Safari or Google Chrome
This method will work in both Safari and Chrome.
GET THE XPATH
We only need to use Chrome to get the XPath:
(Safari does not have the XPath tool)
- Open your web page in Chrome (just one time)
- Right-click on the link of interest, and select "Inspect"
- This will open the Chrome Developer tool, showing the HTML for the link
- Right-click on the HTML for the link, and select "Copy > Copy Xpath"
- We are now done with Chrome. You can close it.
- In the below Action, "Set KM xPath Variable",
- Paste in the text block -- this is the xpath. It should look someting like this:
POSSIBLE ISSUES WITH XPATH
- The "id" used may be dynamically created, and vary within the page, and in similar pages from the same web site. In this case, it may be not be reliable.
- If the HTML Element of interest does not have an "id" attribute, the XPath with be a relative path from the nearest element above that does have an "id".
- If the structure of the web page changes, this path could be broken, causing the XPath to fail.
USING THE MACRO:
- Make sure you have completed the above Setup
- Open your Browser to the page of interest
- Trigger this macro
- 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 Varibles or Clipboards
(1) Keyboard Maestro Ver 7.2.1+
(2) Yosemite (10.10.5)+
(3) Either Safari or Google Chrome