-
Notifications
You must be signed in to change notification settings - Fork 0
Locating elements
The browser supports a list of methods that will return an element object methods called on that element object will locate the element
This library supports locating objects by arbitrary attributes, with the value being a String or Regex
The regex support is limited to anchors, and the case insensitive flag
Given the following html
<body>
<div id="this-is-a-div">Div content</div>
</body>div = browser.div(id: "this-is-a-div")
# or
div = browser.div(id: /THIS-IS-A-DIV/i)
div.text # Div contentElements can be located from a collection, and nested.
This will find the a tag with an id of link inside the second div found in the dom, and click it
browser.divs[1].link(id: "link").clickIf the element is stored to a variable, and is already located, it will use that id to interact with it by default
This could cause issues with a StaleElementReferenceException if the id becomes out of scope.
By using the force: true option, the element as well as all of it's ancestors will be relocated.
div = browser.body.div(id: "div")
div.text
browser.goto "http://www.another.page.com"
div.text # raises StaleElementReferenceExcpetion
div.text(force: true) # relocates the div and body elementsElements can also be located by using xpath or css directly.
This is highly not recommended, as elements that use these attributes cannot be force relocated, and will have unexpected consequences.