我正在使用守夜人来测试div,并在html上使用'data'属性的正确值来检查div,以检查单击后每个div是否转到正确的url。但是我找不到一个正确的解决方案来一起编写div的脚本。有人可以帮我吗?
module.exports = {
'test case': function(client) {
client
.url()
.waitForElementVisible('body',1000)
*** go to a page and then execute this: ***
.execute (function (){
var list = document.getElementsByClassName('promo');
for (var i = 0; i < list.length; i++) {
var num = list[i].getAttribute('data');
//only data value equals to 4 numbers, click on that element
if(/^d{4}$/.test(num)) {
var a = i,
selector = "#container > div > div:nth-child("+a+") > div"
//code doesn't work! No div is clicked!
return client.click(selector);
}
//after redirecting to the new page, find element there.
client.waitForElementPresent('#form > button')
.expect.element('#form > button')
.text.to.contain("some word");
}