Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot iterate over ElementsWrapperList #1078

Closed
alohasick opened this issue Feb 6, 2020 · 2 comments
Closed

Cannot iterate over ElementsWrapperList #1078

alohasick opened this issue Feb 6, 2020 · 2 comments

Comments

@alohasick
Copy link

I have a return from $ selector (let's call it variable X) which when I call X.elements() it indicates a list with 3 elements but I cannot iterate over it. Also, X.elements().length returns undefined.

Expected behavior

According to documentation an ElementWrapperList "exposes a method elements() which gives the actual list of element wrappers. It can be used to loop over the elements." So I should be able to iterate over it

Actual behavior

The return when I try to call a forEach is the following:

X.elements().forEach(function(value, key) {
console.log(key);
})
Thrown:
X.elements(...).forEach is not a function

Versions

node version v13.0.1
taiko version 1.0.3 (Chromium: 81.0.3994.0)
@saikrishna321
Copy link
Member

@alohasick

const { openBrowser, goto, write, press, $, closeBrowser } = require('taiko');
(async () => {
    try {
        await openBrowser();
        await goto('google.com');
        await write('taiko.js');
        await press('Enter');
        (await $('a cite').elements()).forEach(async (ele) => {
           console.log(await ele.text());
        });
    } catch (error) {
        console.error(error);
    } finally {
        await closeBrowser();
    }
})();

Output:

github.com › getgauge › taiko
taiko.gauge.org
gauge.org › gauge-taiko
blog.getgauge.io › introducing-taiko-1895e6eb9cc
www.thoughtworks.com › radar › languages-and-frameworks › taiko
spectrum.chat › taiko › general
stackoverflow.com › questions › tagged › getgauge
medium.com › no-more-flaky-tests-automate-modern-web-applicatio...
www.findbestopensource.com › product › getgauge-taiko
www.reddit.com › softwaretesting › comments › taiko_an_open_sour...

@alohasick
Copy link
Author

Well, that worked. Thanks, @saikrishna321!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants