question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to get one of the elements if the finder matched more than one?

See original GitHub issue

With the finder from appium-flutter-driver, sometimes I got more than one element returned. Then if I do another API call, it returns Bad state: Too many elements. For example, in the code below, if there are more than one widgets with the same text:

from appium_flutter_finder import FlutterElement, FlutterFinder

finder = FlutterFinder()
text_finder = finder.by_text(text)
element = FlutterElement(driver, text_finder)
   
print(element.text)

the last line will raise:

(<class 'selenium.common.exceptions.WebDriverException'>, WebDriverException('An unknown server-side error occurred while processing the command. Original error: Cannot execute command get_text, server reponse {\n  "isError": true,\n  "response": "Uncaught extension error while executing get_text: Bad state: Too many elements\\n#0      Iterable.single (dart:core/iterable.dart:560)\\n#1      FlutterDriverExtension._getText (package:flutter_driver/src/extension/extension.dart:625)\\n<asynchronous suspension>\\n#2      FlutterDriverExtension.call (package:flutter_driver/src/extension/extension.dart:273)\\n<asynchronous suspension>\\n#3      BindingBase.registerServiceExtension.<anonymous closure> (package:flutter/src/foundation/binding.dart:547)\\n<asynchronous suspension>\\n",\n  "type": "_extensionType",\n  "method": "ext.flutter.driver"\n}', None, None), <traceback object at 0x102059180>)

If I call element[0].text, I will get (<class 'TypeError'>, TypeError("'FlutterElement' object is not subscriptable"), <traceback object at 0x10d001600>).

So my question is, how can I get one of the elements if the finder matched several widgets? Any help is appreciated. 🙏

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
GowthamReddyAmbaticommented, Oct 30, 2021

@hex0cter I’m also looking for a solution to the same issue.

0reactions
KazuCocoacommented, Jun 19, 2022

Perhaps currently this is a flutter (or flutter_driver by Flutter team) limitation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get one of the elements if the finder matched ... - GitHub
With the finder from appium-flutter-driver, sometimes I got more than one element returned. Then if I do another API call, it returns Bad ......
Read more >
Keep only one element of each group of elements who match ...
The pythonic way is to rename your match method to __eq__ . Then you can do things like element in list with your...
Read more >
Regular Expressions in A Better Finder Select - publicspace.net
If the RE could match more than one substring starting at that point, its choice is determined by its preference: either the longest...
Read more >
Finders - Kofax Product Documentation
To include an element in the finder evaluation, right-click an element and select Include Cell When Finding. To exclude an element, right-click a...
Read more >
ElementArrayFinder - Protractor
Count the number of elements represented by the ElementArrayFinder. isPresent, Returns true if there are any elements present that match the finder. locator ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found