【问题标题】:Playwright - TypeError: hoverElement.hover is not a functionPlaywright - TypeError:hoverElement.hover 不是函数
【发布时间】:2021-02-15 09:55:37
【问题描述】:

我正在尝试运行它

await hoverElement.hover();

让鼠标悬停在相关元素上

我收到一条错误提示 TypeError: hoverElement.hover is not a function

我正在阅读剧作家 API 文档https://playwright.dev/#version=v1.5.2&path=docs%2Fapi.md&q=elementhandlehoveroptions

我做错了什么?

test('Selection using hover Speak', async () => {

if (EnableTests.run_hover_speak === "true") {

    const expectedResult = TestPage.Div2_Expected_Result;
    const hoverElement = TestPage.Div2_css;

    await test_functions._hoverSpeak(page);
    await hoverElement.hover();

    const highlightedText =  await test_functions._hiliteSelection(page);
    const actual = JSON.stringify(highlightedText); console.log("ACTUAL RESPONSE " + actual);
    const expected = JSON.stringify(expectedResult); console.log("EXPECTED RESPONSE " + expected);
    assert(expected === actual);

};

});

【问题讨论】:

  • 你能多分享一点你的代码吗?
  • 听起来 hoverElement 不正确
  • 我在帖子中分享了更多代码

标签: javascript testing automation playwright


【解决方案1】:

如果hoverElement.hover 不是一个函数,那么它暗示hoverElement(因此TestPage.Div2_css)可能不是一个合适的Playwright elementHandle 对象。我无法从您的代码中看到您从哪里获得 TestPage,但可能是 Div2_css 是对普通 DOM 节点或其 CSS 的引用,而不是 elementHandle

要解决此问题,您可能需要使用 page.$('.div2') 之类的东西分配 hoverElement(将 .div2 替换为合适的 selector 以定位您想要悬停的元素)。

【讨论】:

    猜你喜欢
    • 2023-03-21
    • 2022-12-14
    • 2022-10-18
    • 1970-01-01
    • 2021-09-12
    • 2020-11-23
    • 2021-06-04
    • 2021-07-13
    • 2022-11-22
    相关资源
    最近更新 更多