【问题标题】:Unable to get isDisabled() to work in Playwright无法让 isDisabled() 在 Playwright 中工作
【发布时间】:2021-09-22 09:04:34
【问题描述】:

我需要检查一个按钮是否被禁用(检查表格的最后一页)。有两个具有相同的id(表格的顶部和底部)。

const nextPageButtons = await this.page.$$('button#_btnNext'); // nextPageButtons.length is 2, chekced via console.log
const nextPageButtonState = await nextPageButtons[0].isDisabled();

但是当我执行上述操作时,我得到:elementHandle.isDisabled: Unable to take element handle from a different document.

为什么这不起作用?

【问题讨论】:

  • 你试过this.page.isDisabled('button#_btnNext')吗?它会检查第一个。
  • 更多的是观察而不是答案,但是如果您可以控制页面内容,则应该修复重复的 ID,因为 ID 应该是唯一的
  • @sahmeepee 我们没有,它是由第三方库生成的
  • @hardkoded 这行得通,但我想学习和理解这个..根据文档页面。$$(selector) 返回 Promise>,所以 nextPageButtons[0] 就是. elementHandle.isDisabled() 返回 Promise。那么为什么它会认为这个 ElementHandle 是“来自不同的文档”呢?
  • 您确定您的页面在这两者之间没有变化吗?可能在第一次调用和第二次调用之间,您的元素具有相同的 ID,但这些元素与您之前获得的元素不同。

标签: javascript playwright


【解决方案1】:

所以,这行得通:

const nextPageButtons = await this.page.$$('button#_btnNext');
const nextPageButton1 = await nextPageButtons[0];
const nextPageButton1State = await nextPageButtonsState.isDisabled();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-15
    • 1970-01-01
    • 2018-02-26
    • 2019-07-06
    • 2015-11-27
    • 2012-10-16
    • 2010-11-30
    • 2013-10-26
    相关资源
    最近更新 更多