使用递归找不到元素之后才发现它是可见 [英] Cannot locate element using recursion after it found it as visible

查看:304
本文介绍了使用递归找不到元素之后才发现它是可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题:

我试图点击与Nightwatch下拉选项,使用部分页面对象。我不知道这是否是与段声明一个问题,或者我想的东西范围有关。的问题是,它找到的元素作为可见的,但是当它试图点击它将引发错误,它可以不使用递归找到它。

I am trying to click options in a dropdown with Nightwatch, using sections in page objects. I'm not sure if it's a problem with the section declaration or i'm missing something scope-related. Problem is that it finds the element as visible, but when it tries to click it will throw error that it cannot locate it using recursion.

可能我尝试做什么用的部分来解决这个问题?

What could i try to do to fix this issue using sections?

在测试:

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

            }}}}

下面是我的源$ C ​​$ C:

Here is my source code:

当我运行这片核心,似乎找到了部分,认定元素可见(我也可以清楚地看到它打开的下拉菜单,显示的选项),但试图单击任何选项时,我得到的错误: 错误:无法找到元素:第[名称= setResults],元素[名称= @ set18]使用:递归

When i run this piece of core, it seems to find the section, finds the element visible (i also can clearly see that it opens the dropdown and shows the options) but when trying to click any option, i get the error: ERROR: Unable to locate element: Section[name=setResults], Element[name=@set18]" using: recursion

下面是完整的错误:

我尝试:

我试图声明 set18 选择作为一个单独的元素,而不是部分的内部,一切工作正常这种方式,但不会在段内工作。我也曾尝试所有可用来定义部分的选择的选择,但它不会与任何人合作。

I have tried to declare that set18 selector as an individual element instead of inside of the section and everything works fine this way, but won't work inside of the section. I have also tried all the selectors available to define the section's selector, but it won't work with any of them.

推荐答案

这就是我与做(笑)
我假设步骤将是(Dropbox的发现 - 点击下拉框 - 选择一个值)。

This is what i am doing with(LOL) I assume steps would be (find dropbox - click dropbox - select value).

var getValueElement = {
        getValueSelector: function (x) {
            return 'li[data-value="'+ x + '"]';
        }
}; 

module.exports = {
    //[.. other elements and commands..]
    sections: {
        setResults: {
            commands:[getValueElement],
            selector: 'div[class*="select-theme-result"', //* mean contains,sometime class is too long and unique,also because i am lazy.
            elements: {
                setHighlight:'li[class*="select-option-highlight"]',
                setSelected:'li[class*="select-option-selected"]', 
                //set18: 'li[data-value="18"]',
                //set36: 'li[data-value="36"]' 
                // i think getValueFunction is better,what if you have 100+ of set.

            }}}}

在您的测试

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

诗:在我的情况(我想你的情况也有),Dropbox的或任何一个小的第三方的js框架,多次使用你的Web应用程序,这样更能为它创建一个不同的PageObject,使pageObject /段很简单越好。

Ps:in my case(i think your case also), dropbox or any small third-party js framework which is used many times in your web app, so better create a different PageObject for it,make pageObject/section is simple as possible.

这篇关于使用递归找不到元素之后才发现它是可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆