简体   繁体   English

Browser.execute为所有返回Undefined

[英]Browser.execute is returning Undefined for all

I am fetching few values from the Web Page using custom javascript in Nightwatch. 我正在使用Nightwatch中的自定义javascript从网页中获取一些值。

browser.execute(function () {
    priceValues = {
        total: document.querySelectorAll('someLocator').innerText,
        individualPrice: document.querySelectorAll('someLocator').innerText,
        discount: document.querySelectorAll('someLocator').innerText,
    };
    return priceValues;
}, [], function (result) {
    totalPrice = result.value.total;
    individual = result.value.individualPrice;
    discountPrice = result.value.discount;
});

The problem I am facing is that for some tests I don't have the discount so I am getting undefined there, but due to this the other two total and individualprice whose values are present are also getting undefined. 我面临的问题是,对于某些测试,我没有折扣,因此在那儿我不确定,但是由于这个原因,存在值的其他两个总计个别价格也都不确定。 It would be great if someone could point out where am I doing wrong. 如果有人可以指出我在哪里做错了,那将是很好的。

I was able to do it with the below block of code: 我能够使用下面的代码块来做到这一点:

browser.execute(function () {
    priceValues = {
        total: document.querySelectorAll('someLocator').innerText,
        individualPrice: document.querySelectorAll('someLocator').innerText,
    };
    var discount = document.querySelectorAll('someLocator'),

    if (discount && discount.innerText) {
        priceValues.discount = discount.innerText;
    }
    return priceValues;
}, [], function (result) {
    totalPrice = result.value.total;
    individual = result.value.individualPrice;
    discountPrice = result.value.discount;
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM