kgress / scaffold

A Java based Selenium WebDriver abstraction
MIT License
4 stars 7 forks source link

findElements() unable to process immediate relationship by locators #147

Closed kgress closed 2 years ago

kgress commented 2 years ago

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:

<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:

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:

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