在我的2e2测试w Nightwatch.js中,我可以使用WebDriver协议获取元素,但结果(res.value)是一个元素ID数组...
如何获取这些元素的详细信息?
[ { ELEMENT: '0.03261545200301663-4' },
{ ELEMENT: '0.03261545200301663-5' } ] ' length: ' 2
FIRST ELEMENT ID: 0.03261545200301663-4
FIRST ELEMENT TAG NAME: undefined
E2E / test.js
module.exports = {
'Add shoppinglist': (browser) => {
const devServer = browser.globals.devServerURL
// open the browser and wait for #app to be on the page
browser.url(devServer).waitForElementVisible('#app', 5000)
// check the title of the current active tab
browser.expect.element('ul.nav-tabs li.active a').text.to.equal('Groceries')
// click on add shopping list plus button
browser.click('#addShoppingListIcon')
// get shopping list tab title elements
browser.elements('css selector', 'ul.nav-tabs li', (res) => {
console.log(res.value, ' length: ', res.value.length)
console.log('FIRST ELEMENT ID: ', res.value[0].ELEMENT)
console.log('FIRST ELEMENT TAG NAME: ', res.value[0].tag_name)
console.log('FIRST ELEMENT CSS CLASS: ', res.value[0].style('class'))
})
browser.pause(1000)
// check the title of the active tab
browser.expect.element('ul.nav-tabs li.active a').text.to.equal('New Shopping List')
// check the title of the active content panel
browser.expect.element('#app .tab-content .tab-pane.active h2').text.to.equal('New Shopping List')
// check the default value of the footer change title input field
browser.getValue('#app .tab-content .tab-pane.active .footer input.input[name=title]', (result) => {
browser.assert.equal(result.value, 'New Shopping List')
})
browser.end()
}
}
答案 0 :(得分:1)
应该使用ELEMENT作为后续请求的ID ...
browser.elements('css selector', 'ul.nav-tabs li', (res) => {
console.log(res.value, ' length: ', res.value.length)
console.log('FIRST ELEMENT ID: ', res.value[0].ELEMENT)
browser.elementIdAttribute(res.value[0].ELEMENT, 'class', (value) => {
console.log('FIRST ELEMENT CLASS ATTRIBUTE: ', value)
})
})
console.log
FIRST ELEMENT CLASS ATTRIBUTE: { sessionId: '13a05b81a71d8860df5432fc7e585ab5',
status: 0,
value: 'active' }