Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple elements to be found by browserSideFind & find(...) #29

Open
MexicanAce opened this issue Aug 27, 2019 · 1 comment
Open

Comments

@MexicanAce
Copy link

Problem

When attempting to use the find(...) (or see(...)) action helper, I'm unable to select a specific element when multiple are found on the page. Instead, I would be presented with the following error:

> see('Aug 26, 2019');

> "Looking for Aug 26, 2019 failed. More than one element is displayed, number of displayed elements: 8
Elements:
<td _ngcontent-wup-c43="" class="mat-cell cdk-column-created mat-column-created ng-star-inserted" mat-cell="" role="gridcell">Aug 26, 2019</td>
<td _ngcontent-wup-c43="" class="mat-cell cdk-column-created mat-column-created ng-star-inserted" mat-cell="" role="gridcell">Aug 26, 2019</td>
<td _ngcontent-wup-c43="" class="mat-cell cdk-column-created mat-column-created ng-star-inserted" mat-cell="" role="gridcell">Aug 26, 2019</td>
...
"

Solution

  1. Update the findGlobal(locator) function to look for a new property on the locator, e.g. locator.index and/or locator.wantMultiple
  2. Update the opt_options of browserSideFind(locators, opt_options) to include the new property
  3. Update retrying_find to return the new possible type of WebElement[]
  4. Update BrowserSideOptions with the new property (e.g. locator.wantMultiple)
  5. Update getElement(locator: FlexibleLocator, description: string): Promise<WebElement> to also accept and use options: BrowserSideOptions and return Promise<WebElement|WebElement[]>

Ultimately, this would result in the end user having the following experience:

find('Aug 26, 2019', {wantMultiple: true})[2].click();
// or
const dates = below('Created').find('Aug 26, 2019', {wantMultiple: true});
expect(dates.length).toBe(8);
@MexicanAce
Copy link
Author

Alternatively, you could always pass in the option {wantMultiple: true} for find(...), thus providing the following experience:

find('Aug 26 2019')[2].click();
// or
// Default return the first element if the WebElement[] length is equal to 1 (backwards compatibility)
find('Aug 26 2019');
// or
const dates = below('Created').find('Aug 26, 2019');
expect(dates.length).toBe(8);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant