Finding DOM Elements¶
Sometimes it is necessary to use the precision of a DOM-based search. You can search the DOM by using an XPATH query or a CSS selector. The easiest way to obtain either one of these expressions is to do the following:
- Enter inspect mode in Chrome's developer tools UI (press F12 then click the arrow button)
- Right-click on the element you want to find
- Click on the Copy menu
- Choose Copy XPath or Copy Selector from the copy submenu
- Paste the copied expression into the "Patterns" property of the find element action
Header:
Name: Find Dude Info
ApplicationName: Wikipedia
RequiresLogin: False
Actions:
- Navigate:
Url: '{endpoint}/'
- WaitForContent: {}
- Snapshot: {}
- FindElementByCSSSelector:
Patterns:
- #mw-content-text > div > table:nth-child(4) > tbody > tr:nth-child(2) > td > div
Another characteristic of this type of find is that you can chain together consecutive DOM-based find actions and each subsequent find will be made relative to the previous one. In order for this to work properly the previous find should resolve to exactly one element.
Remember if you want to click/hover an element by searching an XPATH or CSS Selector you must use the FindElementXXX methods and not provide any patterns in the click/hover actions. The element clicked or hovered will be determined from the result of the previous find element.
The following find methods are available for DOM-based elements:
- FindElementByXPath
- FindElementsByXPath
- FindElementByCSSSelector
- FindElementsByCSSSelector