This version introduces the
child_nodes() utility functions. These functions allow for easy fetching of nodes which would otherwise be harder to access in plain WebDriver.
Internally the tests that test Germanium itself were cleaned up a bit.
Let’s assume you write an integration test using Germanium, and you decide to iterate over some nodes under another element that you already have. Here’s how you can do it.
parent_node() is pretty obvious, since it has only one parameter, named selector:
parent = parent_node('.child-element')
Awesome? Pretty awesome, since we can use selectors not just elements, but let’s see further.
child_nodes() function has yet another parameter named
only_elements that by default is
True. Why that? Let’s find out.
For example for the given HTML:
items = child_nodes("#parent")
This will return a list of 2 elements, with the child1 and child2, since
only_elements is set by default to
This is what anyone would expect.
Instead, setting the
False, the call will return 5 elements (!), 4 elements on IE (?!?), since there are 3 (2 on IE) whitespace nodes in the
- Before the
#child1(this one is dropped by IE in certain circumstances,
<sarcasm>good job IE!
- And after
items = child_nodes('#parent', only_elements=False)
This is actually what the browsers return. Text nodes are also elements in the DOM tree, so they will be returned. Imagine how mental would be to try testing with indexes, since the first text node might or might not be there.
Thus you don’t need to call some fancy JS, or write trippy
if statements, since Germanium will do it for you. Also using Germanium you can enjoy the full selectors and locators support that Germanium offers, so even as you can see in the current example, you don’t need to find first the element, and only then get its children.
So keep testing with Germanium you awesome you!