Flutter driver: cant find element (text) on the screen

1.6k Views Asked by At

The element I need to find is situated (in the child element):

 static Widget _buildProjectCategoryWidget(BuildContext context, String name) {
final themeData = Theme.of(context);
final primaryTextTheme = themeData.primaryTextTheme;
return Container(
  padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 5.0),
  decoration: BoxDecoration(borderRadius: BorderRadius.circular(13.0), color: FlAppStyles.altButtonColor),
  child: Text(name, style: primaryTextTheme.textSmall),
);

I tried to find the child element with this, but I have DriverError: Failed to fulfill Tap due to remote error:

SerializableFinder message = find.text("mytext");
    await driver.waitFor(message);
    expect(await driver.getText(message), "mytext"); await driver.tap(buttonChangeProfession);
    

Im a beginner to flutter integration testing, dont know what is wrong, please help. I also tried adding a key and find element by it, but the point is I need to find the text of that element.

2

There are 2 best solutions below

0
On

See: https://github.com/ashwithpoojary98/javaflutterfinder/issues/8 Issue in ashwithpoojary98

Text and Visibility check:
The getText() and isDisplayed() methods are not implemented in the Element class of Flutter Driver. Instead, you can use the getTextFinder() and waitFor() methods to retrieve the text of an element and check if it is visible.
final element = find.byValueKey('my_element_key');
final textFinder = find.descendant(of: element, matching: find.text('my_text'));

await driver.waitFor(element);
final text = await driver.getText(textFinder);
print(text);

await driver.waitFor(element);
final isVisible = await driver.waitFor(element).isPresent;
print(isVisible);

0
On

Try this, if you want to verify that this text exists on screen:

expect(
      await driver.getText(find.text("enter text you want to find")),
      "enter text you want to find");

Try this, if you want to tap on that text:

  final elementFinder= find.text('enter text you want to tap');
  await driver.waitFor(elementFinder);
  await driver.tap(elementFinder);

Please get that text by inspecting using Devtool if you are not sure about it, hope this helps