When using BaseWebElement#findElements() with a CSS By locator, a deep dom search is occurring and does not provide functionality for an immediate parent to child relationship. For example, the followin DOM structure:
<div id="inventory_list>
<div id="inventory_item>
<div id="inventory_item_img>
... 7 more div elements here
</div>
<div id="inventory_item>...</div>
<div id="inventory_item>...</div>
<div id="inventory_item>...</div>
<div id="inventory_item>...</div>
</div>
We want to find all #inventory_item elements and put them in a list with By locators. We would expect an immediate parent child relationship as #inventory_list and #inventory_item, relatively. With this in mind, findElements() should return us a list of appended By locators as the following:
inventory_list #inventory_item:nth-child(1)
inventory_list #inventory_item:nth-child(2)
inventory_list #inventory_item:nth-child(3)
inventory_list #inventory_item:nth-child(4)
inventory_list #inventory_item:nth-child(5)
The problem is that findElements() is checking all children under the parent and not just the immediate children. Because of the, following the same example above, let's assume there are 8 additional div's under each #inventory_item element. The findElements() method returns the appended By locators as the following:
inventory_list #inventory_item:nth-child(1)
inventory_list #inventory_item:nth-child(9)
inventory_list #inventory_item:nth-child(17)
inventory_list #inventory_item:nth-child(25)
inventory_list #inventory_item:nth-child(33)
Expected
findElements() should be able to provide a lookup for all elements with By locator magic either as a deep search or an immediate parent/child relationship. However, we need to still allow the existing functionality for how the method is currently written. As a quick fix, I think we should update the existing findElements() method to overload a newly written findElements() method that introduces a new boolean param called immediateRelationship. This boolean can control whether or not the intent of the findElements() call is a deep search through the dom or with an immediate parent/child lookup. The updated overloaded findElements() method will call the new method with the parameter of false, since it is always looking for a deep search.
A/C
Scaffold should be able to find elements using a deep search
Scaffold should be able to find elements using an immediate parent/child relationship
Bug
When using BaseWebElement#findElements() with a CSS
By
locator, a deep dom search is occurring and does not provide functionality for an immediate parent to child relationship. For example, the followin DOM structure:We want to find all
#inventory_item
elements and put them in a list withBy
locators. We would expect an immediate parent child relationship as#inventory_list
and#inventory_item
, relatively. With this in mind,findElements()
should return us a list of appendedBy
locators as the following:inventory_list #inventory_item:nth-child(1)
inventory_list #inventory_item:nth-child(2)
inventory_list #inventory_item:nth-child(3)
inventory_list #inventory_item:nth-child(4)
inventory_list #inventory_item:nth-child(5)
The problem is that
findElements()
is checking all children under the parent and not just the immediate children. Because of the, following the same example above, let's assume there are 8 additional div's under each#inventory_item
element. ThefindElements()
method returns the appendedBy
locators as the following:inventory_list #inventory_item:nth-child(1)
inventory_list #inventory_item:nth-child(9)
inventory_list #inventory_item:nth-child(17)
inventory_list #inventory_item:nth-child(25)
inventory_list #inventory_item:nth-child(33)
Expected
findElements()
should be able to provide a lookup for all elements withBy
locator magic either as a deep search or an immediate parent/child relationship. However, we need to still allow the existing functionality for how the method is currently written. As a quick fix, I think we should update the existingfindElements()
method to overload a newly writtenfindElements()
method that introduces a new boolean param calledimmediateRelationship
. This boolean can control whether or not the intent of thefindElements()
call is a deep search through the dom or with an immediate parent/child lookup. The updated overloadedfindElements()
method will call the new method with the parameter offalse
, since it is always looking for a deep search.A/C