pbuddy
pbuddy

Reputation: 47

Playwright - TypeError: hoverElement.hover is not a function

I am trying to run this

await hoverElement.hover();

so that the mouse will hover over the element in question

I get an error saying TypeError: hoverElement.hover is not a function

I am reading from the playwright API documentation https://playwright.dev/#version=v1.5.2&path=docs%2Fapi.md&q=elementhandlehoveroptions

What am I doing wrong?

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

};

});

Upvotes: 0

Views: 4469

Answers (1)

JRI
JRI

Reputation: 1952

If hoverElement.hover is not a function, then it implies that hoverElement (and therefore TestPage.Div2_css) is probably not a proper Playwright elementHandle object. I can't see from your code where you get TestPage from, but it might be that Div2_css is a reference to a plain DOM node, or its CSS, rather than an elementHandle.

To fix this, you might need to assign hoverElement using something like page.$('.div2') (replace .div2 with a suitable selector to target the element you want to hover over).

Upvotes: 0

Related Questions