getgauge / taiko

A node.js library for testing modern web applications
https://taiko.dev
MIT License
3.57k stars 453 forks source link

isVisible() is always returning false when used along with text("<text_of_a_element>") #2607

Open gokultw opened 2 years ago

gokultw commented 2 years ago

Describe the bug isVisible() is always returning false when used along with text("<text_of_a_element>"). await highlight(text("<text_of_a_element>")); is highlighting the element but isVisible() is returning false, if we use a selector like $, button, link etc then we are getting the expected result.

To Reproduce Script to reproduce the behavior:

(async () => {
    try {
        await openBrowser();
        await goto("Google.com");
        await highlight(text("India"));
        await console.log(await text("India").isVisible());
    } catch (error) {
        console.error(error);
    } finally {
        await closeBrowser();
    }
})();

Expected behavior isVisible() Should return true since the text is available and visible on the page.

Versions:

Additional context The below code snippet is working fine with $ instead of text

(async () => {
    try {
        await openBrowser();
        await goto("Google.com");
        await highlight(text("India"));
        await console.log(await $("//DIV[text()='India']").isVisible());
    } catch (error) {
        console.error(error);
    } finally {
        await closeBrowser();
    }
})();
jbpotonnier commented 1 year ago

It looks like it may be a regression introduced by https://github.com/getgauge/taiko/pull/2288

ghost commented 1 year ago

@gokultw I have had the same issue while using Taiko. The problem in my case was that isVisible()returned false when the element I was looking for existed multiple times on the page. So this would be my first guess that the text India is found multiple times on the page but that the Xpath "//DIV[text()='India']" is unique and therefore isVisible() works correctly.