如何返回getTexts for Isexisitation的元素数组

发布于 2025-02-09 23:48:43 字数 1199 浏览 1 评论 0原文

我的目标是从一个分享三个元素的单个定位器中返回一组文本,它们存储在元素名称选择器的数组中(作为选择器存储三个元素),在返回之前,我希望他们通过Isexisting()标志,但是它将“ TypeError:selector.issiveisting不是一个函数”抛出,如果我删除代码的归化部分,则可以正常工作并返回三个文本值。我的代码是:

  async function getTreeTexts(browser, sidebar, parentClass, treeClass, spanClass = 'caption') {
    //await browser.ideOpenSidebar(sidebar)
    var cl = c => c ? '.' + c : '';
    var selector  = await browser.$$(`${cl(parentClass)} .ace_tree${cl(treeClass)} .tree-row span${cl(spanClass)}`);
    await browser.ideOpenSidebar(sidebar)
    await selector.isExisting().then(async function (exists) {
        if (exists) {
        // Depending on the number of matches, items can be a string or an array of strings. Coerce to array.            
            let configs = [];
            for (let element of selector) {
                try {
                    let text = await element.getText();
                    configs.push(text);
                } catch (err) {
                    configs.push('[deleted]');
                }
            }
            return configs;
        } else {
            return [];
        }
    });
}

如果我做错了什么,有人可以在这里帮助我吗? (我的猜测是,Isexisiting()不同时处理所有三个元素)

I am aiming to return a set of texts from a single locator that shares three elements and they are stored in an array of elements name selector (being selector storing three elements)and before it returns texts I want them to pass isExisting() flag but it throws "TypeError: selector.isExisting is not a function" if I remove isExisting part of code then it works fine and return the three text values. My code is:

  async function getTreeTexts(browser, sidebar, parentClass, treeClass, spanClass = 'caption') {
    //await browser.ideOpenSidebar(sidebar)
    var cl = c => c ? '.' + c : '';
    var selector  = await browser.$(`${cl(parentClass)} .ace_tree${cl(treeClass)} .tree-row span${cl(spanClass)}`);
    await browser.ideOpenSidebar(sidebar)
    await selector.isExisting().then(async function (exists) {
        if (exists) {
        // Depending on the number of matches, items can be a string or an array of strings. Coerce to array.            
            let configs = [];
            for (let element of selector) {
                try {
                    let text = await element.getText();
                    configs.push(text);
                } catch (err) {
                    configs.push('[deleted]');
                }
            }
            return configs;
        } else {
            return [];
        }
    });
}

Can someone please assist me here if I am doing something wrong? (my guess is, isExisiting() not handling all three elements at the same time)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文