Javascript 在发现元素可见后,无法使用递归定位该元素

Javascript 在发现元素可见后,无法使用递归定位该元素,javascript,recursion,automated-tests,nightwatch.js,Javascript,Recursion,Automated Tests,Nightwatch.js,我的问题: var searchKeywordCommands = { myFunction: function (section, x) { section.expect.element('@set18').to.be.visible.before(2000); if (x == '18') section.click('@set18'); //[...] }; module.exports = { //[.. other el

我的问题:

var searchKeywordCommands = {
    myFunction: function (section, x) {
        section.expect.element('@set18').to.be.visible.before(2000);
        if (x == '18') section.click('@set18');
        //[...]
};

module.exports = {
    //[.. other elements and commands..]
    sections: {
        setResults: {
            selector: '.select-theme-result', //have also tried with '.select-content' and '.select-options' but with the same result
            elements: {
                set18: '.select-option[data-value="18"]',
                set36: '.select-option[data-value="36"]' //etc

            }}}}
我试图用Nightwatch单击下拉菜单中的选项,使用页面对象中的部分。我不确定这是否与节声明有关,或者我缺少了与范围相关的内容。问题是它发现元素是可见的,但当它试图单击它时,它将抛出错误,即它无法使用递归找到它

我可以尝试使用节来解决此问题吗

在测试中:

var myPage = browser.page.searchPageObject();
var mySection = searchPage.section.setResults;

// [finding and clicking the dropdown so it opens and displays the options]
browser.pause (3000);

browser.expect.section('@setResults').to.be.visible.before(1000);
myPage.myFunction(mySection, '18');
在页面对象中:

var searchKeywordCommands = {
    myFunction: function (section, x) {
        section.expect.element('@set18').to.be.visible.before(2000);
        if (x == '18') section.click('@set18');
        //[...]
};

module.exports = {
    //[.. other elements and commands..]
    sections: {
        setResults: {
            selector: '.select-theme-result', //have also tried with '.select-content' and '.select-options' but with the same result
            elements: {
                set18: '.select-option[data-value="18"]',
                set36: '.select-option[data-value="36"]' //etc

            }}}}
以下是我的源代码:

当我运行这段核心时,它似乎找到了部分,找到了可见的元素(我也可以清楚地看到它打开了下拉列表并显示了选项),但是当尝试单击任何选项时,我得到了错误:
错误:找不到元素:部分[name=setResults],元素[name=@set18]“使用:递归

以下是全部错误:

我的尝试:

var searchKeywordCommands = {
    myFunction: function (section, x) {
        section.expect.element('@set18').to.be.visible.before(2000);
        if (x == '18') section.click('@set18');
        //[...]
};

module.exports = {
    //[.. other elements and commands..]
    sections: {
        setResults: {
            selector: '.select-theme-result', //have also tried with '.select-content' and '.select-options' but with the same result
            elements: {
                set18: '.select-option[data-value="18"]',
                set36: '.select-option[data-value="36"]' //etc

            }}}}

我试图将
set18
选择器声明为单个元素,而不是在节内部,这样一切都可以正常工作,但在节内部不起作用。我还尝试了所有可用的选择器来定义节的选择器,但它们中的任何一个都不起作用

这就是我正在做的(LOL) 我假设步骤是(查找dropbox-单击dropbox-选择值)

在你的测试中

var myPage = browser.page.searchPageObject();
var mySection = searchPage.section.setResults;

// [finding and clicking the dropdown so it opens and displays the options]
mySection
     .click('@dropboxSelector')
     .waitForElementVisible('@setHighlight',5000,false,
          function(){
            var set18 = mySection.getValueElement(18);
            mySection.click(set18);
            });

Ps:在我的情况下(我也认为是你的情况),dropbox或任何在你的web应用程序中多次使用的小型第三方js框架,因此最好为它创建一个不同的PageObject,使PageObject/section尽可能简单。

这就是我正在做的(LOL) 我假设步骤是(查找dropbox-单击dropbox-选择值)

在你的测试中

var myPage = browser.page.searchPageObject();
var mySection = searchPage.section.setResults;

// [finding and clicking the dropdown so it opens and displays the options]
mySection
     .click('@dropboxSelector')
     .waitForElementVisible('@setHighlight',5000,false,
          function(){
            var set18 = mySection.getValueElement(18);
            mySection.click(set18);
            });

Ps:在我的情况下(我也认为是你的情况),dropbox或任何在你的web应用中多次使用的小型第三方js框架,因此最好为它创建一个不同的PageObject,使PageObject/section尽可能简单。

首先,我如何访问getValueElement函数?它抛出一个错误,即它不是mySection.getValueElement(18)和myPage.getValueElement(18)的函数。好的,我想我已经管理好了,命令中需要一个单独的函数,而不是命令需要一个函数。但现在我得到:错误:无法使用:css选择器定位元素:“li[data value=18]”可以打开浏览器-F12-在元素选项卡中,找到“li[data value=18]”css选择器的最短字符串吗?是的,它当然在那里。但我同时发现了问题,getValueElement函数缺少“”首先,我如何访问getValueElement函数?它抛出一个错误,即它不是mySection.getValueElement(18)和myPage.getValueElement(18)的函数。好的,我想我已经管理好了,命令中需要一个单独的函数,而不是命令需要一个函数。但现在我得到:错误:无法使用:css选择器定位元素:“li[data value=18]”可以打开浏览器-F12-在元素选项卡中,找到“li[data value=18]”css选择器的最短字符串吗?是的,它当然在那里。但我同时发现问题在于getValueElement函数缺少“”