Search code examples
javascriptjavainternleadfoot

Intern framework - LeadFoot - unable to locate element


I am writing functional test cases using leadfoot intern framework. Test Case: Enter the form field and click a button which will open up a bootstrap modal. All i am trying to do is verify the display property of the element present on the modal.

But when i try to find the element by id 'viewBtn' it does not find it and throws: NoSuchElement: [POST http://localhost:4444/wd/hub/session/e23a975b60188479d599d2 43505ce9cb/element/0.1521919297986265-4/element / {"using":"id","value":"viewBtn tBtn"}] no such element: Unable to locate element: {"method":"id","selector":"viewBtn "}

define(function (require){
    var registerSuite = require('intern!object');
    var assert = require('intern/chai!assert');

    registerSuite({
        name:'Test Page',
        'Continue':function(){
            return this.remote
             .get(require.toUrl('http://sdfsdfs'))
             .setFindTimeout(5000)
            .findById('to')
            .click()
            .type('john')
            .end()                      
            .findById('from')
            .click()
            .type('man')            
            .end()          
            .findById('message')
            .click()
            .type('hello')
            .end()          
            .findByCssSelector("[name=formName]").findByClassName('btn')
            .click()
            .end()
            .setFindTimeout(5000)
            .findById('viewBtn')
            .isDisplayed()
            .then(function(text){
                assert.equal(text,'true','Not Displayed');
            })
        }
    });
})

;

Why is it throwing error when the id is present in the element. Also i am calling end method after every find method.?


Solution

  • It looks like you may not be searching in the correct context. In the snippet below, there is only one end between two finds and the findById). This means the context at the point findById('viewButton') is called is the element with name "formName" (so that the findById is only searching within/under the name="formName" element), because only the findByClassName call was ended:

    .findByCssSelector("[name=formName]").findByClassName('btn')
    .click()
    .end()
    .setFindTimeout(5000)
    .findById('viewButton')
    

    To search the entire doc (assuming that's the intention), call end(2) to end both of the finds.

    Also, note that setFindTimeout is persistent, so you only need to call it once unless you're changing the value.