sclevine / agouti

A WebDriver client and acceptance testing library for Go
MIT License
821 stars 105 forks source link

Get to parent from selection #63

Open msecret opened 8 years ago

msecret commented 8 years ago

I notice there's no parent method on the Selection struct. Is there a way to get to a parent from a selection? This is a common pattern that I've found use for while testing frontend code. Here's an example

<ul>
  <li><a>to test</a></li>
  <li><a>another to test</a></li>
</ul>
var sel = page.FindByLink("to test")
// sel.Parent("ul").FindByLink("another to test")

My example is a little more complicated than this but this gives a basic idea. Essentially this allows to use FindByLink for ease of use but limit selection to a certain block from the found link.

sclevine commented 8 years ago

Sorry for the delayed response.

While there isn't inherent support for this in the WebDriver Wire Protocol, various WebDrivers may support it via the XPath parent axis. I'll consider adding this when I have time. Alternatively, feel free to open a PR.

In the meantime, you may be able to accomplish this with FindByXPath.