0

我正在尝试运行它

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

};

});

4

1 回答 1

0

如果hoverElement.hover不是一个函数,那么它意味着hoverElement(因此TestPage.Div2_css)可能不是一个适当的 PlaywrightelementHandle对象。我无法从您的代码中看到您的TestPage来源,但它可能是Div2_css对普通 DOM 节点或其 CSS 的引用,而不是elementHandle.

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

于 2020-11-02T18:56:58.627 回答