【问题标题】:Flutter driver: cant find element (text) on the screen颤振驱动程序:在屏幕上找不到元素(文本)
【发布时间】:2021-03-27 13:43:09
【问题描述】:

我需要找到的元素位于(在子元素中):

 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),
);

我试图用这个找到子元素,但是我有 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);
    

我是flutter集成测试的初学者,不知道哪里出了问题,请帮忙。我也尝试添加一个键并通过它查找元素,但关键是我需要找到该元素的文本。

【问题讨论】:

  • 这将有助于了解完整的错误消息是什么以及查找器buttonChangeProfession 是如何定义的。

标签: flutter testing integration flutter-test flutterdriver


【解决方案1】:

如果您想验证屏幕上是否存在此文本,请尝试以下操作:

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

如果你想点击该文本,试试这个:

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

如果您不确定,请使用 Devtool 检查获取该文本,希望对您有所帮助

【讨论】:

    猜你喜欢
    • 2020-09-08
    • 1970-01-01
    • 2021-07-12
    • 2017-09-14
    • 1970-01-01
    • 1970-01-01
    • 2021-02-24
    • 2017-02-18
    • 2018-08-15
    相关资源
    最近更新 更多