nightwatchjs:使用while循环给出“ - 进程内存不足”

时间:2022-09-06 17:10:23

I am trying:

我在尝试:

while(browser.assert.elementPresent("div[school-addlimit='2']>button[disabled='disabled']")!=null){
            createSchoolPage
                .click_add_button();
        }

if I use for loop without using condition, it works fine.

如果我使用for循环而不使用条件,它工作正常。

What am I doing wrong here?

我在这做错了什么?

1 个解决方案

#1


0  

browser.assert.elementPresent returns reference to browser object so you can chain your commands like browser.assert.elementPresent(".....") .click("......") .doAnotherAssertion("....") Because of that, your loop is infinitive

browser.assert.elementPresent返回对浏览器对象的引用,因此您可以链接命令,如browser.assert.elementPresent(“.....”)。click(“......”).doAnotherAssertion(“... 。)因此,你的循环是不定式的

If you want to check if element presents on the page, and if so, then click on it, do it in that way:

如果要检查页面上是否显示元素,如果是,则单击它,以这种方式执行:

var selector = "div[school-addlimit='2']>button[disabled='disabled']"; browser.element('css selector', selector, function(response) { if (response.status !== -1) { createSchoolPage.click_add_button(); } })

var selector =“div [school-addlimit ='2']>按钮[disabled ='disabled']”; browser.element('css selector',selector,function(response){if(response.status!== -1){createSchoolPage.click_add_button();}})

or

var selector = "div[school-addlimit='2']>button[disabled='disabled']"; browser.waitForElementVisible(selector, defaultMaximumWaitTime, false, function(result) { if (result.value) { createSchoolPage.click_add_button(); } }

var selector =“div [school-addlimit ='2']>按钮[disabled ='disabled']”; browser.waitForElementVisible(selector,defaultMaximumWaitTime,false,function(result){if(result.value){createSchoolPage.click_add_button();}}

update

I see 3 possibilities when element is in DOM but it is not clickable:
* button is hovered by other element
* button is disabled
* button is in DOM but it is not visible

当元素在DOM中但是它不可点击时我看到3种可能性:*按钮被其他元素悬停*按钮被禁用*按钮在DOM中但是它不可见

In first case, you may use https://developer.mozilla.org/en-US/docs/Web/API/Document/elementFromPoint to check if the button is on top

在第一种情况下,您可以使用https://developer.mozilla.org/en-US/docs/Web/API/Document/elementFromPoint检查按钮是否位于顶部

In second case, you need to update your css selector to find element that is not disabled (ex. https://*.com/a/9207343/787828) (or find any element and then check their attributes)

在第二种情况下,您需要更新您的css选择器以查找未禁用的元素(例如https://*.com/a/9207343/787828)(或查找任何元素,然后检查其属性)

In third case, use browser.waitForElementVisible

在第三种情况下,使用browser.waitForElementVisible

#1


0  

browser.assert.elementPresent returns reference to browser object so you can chain your commands like browser.assert.elementPresent(".....") .click("......") .doAnotherAssertion("....") Because of that, your loop is infinitive

browser.assert.elementPresent返回对浏览器对象的引用,因此您可以链接命令,如browser.assert.elementPresent(“.....”)。click(“......”).doAnotherAssertion(“... 。)因此,你的循环是不定式的

If you want to check if element presents on the page, and if so, then click on it, do it in that way:

如果要检查页面上是否显示元素,如果是,则单击它,以这种方式执行:

var selector = "div[school-addlimit='2']>button[disabled='disabled']"; browser.element('css selector', selector, function(response) { if (response.status !== -1) { createSchoolPage.click_add_button(); } })

var selector =“div [school-addlimit ='2']>按钮[disabled ='disabled']”; browser.element('css selector',selector,function(response){if(response.status!== -1){createSchoolPage.click_add_button();}})

or

var selector = "div[school-addlimit='2']>button[disabled='disabled']"; browser.waitForElementVisible(selector, defaultMaximumWaitTime, false, function(result) { if (result.value) { createSchoolPage.click_add_button(); } }

var selector =“div [school-addlimit ='2']>按钮[disabled ='disabled']”; browser.waitForElementVisible(selector,defaultMaximumWaitTime,false,function(result){if(result.value){createSchoolPage.click_add_button();}}

update

I see 3 possibilities when element is in DOM but it is not clickable:
* button is hovered by other element
* button is disabled
* button is in DOM but it is not visible

当元素在DOM中但是它不可点击时我看到3种可能性:*按钮被其他元素悬停*按钮被禁用*按钮在DOM中但是它不可见

In first case, you may use https://developer.mozilla.org/en-US/docs/Web/API/Document/elementFromPoint to check if the button is on top

在第一种情况下,您可以使用https://developer.mozilla.org/en-US/docs/Web/API/Document/elementFromPoint检查按钮是否位于顶部

In second case, you need to update your css selector to find element that is not disabled (ex. https://*.com/a/9207343/787828) (or find any element and then check their attributes)

在第二种情况下,您需要更新您的css选择器以查找未禁用的元素(例如https://*.com/a/9207343/787828)(或查找任何元素,然后检查其属性)

In third case, use browser.waitForElementVisible

在第三种情况下,使用browser.waitForElementVisible