'Flutter Widget Test expansionTile not opening on tester.tap()

I am new to testing widgets in flutter and I have no clue why it doesn't work. My expansionTile:

ExpansionTile(
        title: Padding(
            padding: EdgeInsets.symmetric(vertical: 8),
            child: Table(
              columnWidths: const <int, TableColumnWidth>{
                0: FlexColumnWidth(1),
                1: FlexColumnWidth(2.5),
                2: FlexColumnWidth(1),
              },
              children: [
                TableRow(children: [
                  Container(),
                  Container(TextButton(child: Text('Some title'))),
                  Container(),
                ])
              ],
            )),
        children: [
          Table(
            columnWidths: const <int, TableColumnWidth>{
              0: FlexColumnWidth(1),
              1: FlexColumnWidth(3),
              2: FlexColumnWidth(0.5),
            },
            children: <TableRow>[
              TableRow(children: [
                Container(),
                Container(
                  child: Row(
                    children: [
                    Text('Find me'),
                  ]),
                ),
                Align(),
              ]),
            ],
          ),
        ],
      ),

And this is the test I have now:

testWidgets('Get opties text', (WidgetTester tester) async {
  await _createWidget(tester);
  await tester.pump();

  await tester.ensureVisible(find.byType(ExpansionTile));
  await tester.tap(find.byType(ExpansionTile));
  await tester.pump(Duration(seconds: 15));
  await tester.ensureVisible(find.text('Find me')); //This gives me an error
});

Error: The following StateError was thrown running a test: Bad state: No element



Solution 1:[1]

Hopefully you've already resolved this issue, but if not try tapping on the ExpansionTile's title widget rather than the ExpansionTile itself. You can find by text or by key (if you add a key to the title).

Taken from how the Flutter team test ExpansionTiles:

https://github.com/flutter/flutter/blob/96f977f4df77f9f8069faa09062f58ba5836a9b5/packages/flutter/test/material/expansion_tile_test.dart#L123

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Martin Harrison