2017-10-09 43 views
0

在我2E2测试W¯¯Nightwatch.js,我可以使用webdriver的协议元素,但结果(res.value)是元素ID数组...Vue.js e2e w Nightwatch.js如何获取有关WebElements(WebDriver协议)的详细信息?

我怎样才能得到这些元素的细节?

[ { 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

应该使用元素的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' } 
相关问题