Valentina
Valentina

Reputation: 644

Invalid Locator error

I tried to rewrite my tests in Page Object style but something goes wrong.

I use Class Tab and this is a part of my code:

var World = require('../support/world.js');
const isAllAjaxRequests = require('../scripts/util').isAllAjaxRequests;
const isElementLocatedAndVisible = require('../scripts/util').isElementLocatedAndVisible;

module.exports.Tab = class Tab {

    constructor(data) {
        this.name = "Base";
        this.locators = {
            'nextStepIsLocked': {xpath: '//md-tab-item[@aria-selected="true"]//div[@class="cc-status red"]'},
            'isActiveTab': {xpath: '//md-tab-item[@aria-selected="true"]//span[text()="'+ data + '"]'}
        }
    }

    waitForElement(bySelector) {
        var driver = World.getDriver();
        var self = this;
        //var bySelector = self.locators[bySelector];

        return driver.wait(isAllAjaxRequests(driver), waitTimeOut).then(() => {
            //console.log(bySelector)
            return driver.wait(isElementLocatedAndVisible(bySelector), waitTimeOut);
        });
    }

    tabIsOpen(tabName) {
        var driver = World.getDriver();
        var self = this;
        var bySelector = By.xpath('//md-tab-item[@aria-selected="true"]//span[text()="'+ tabName + '"]');

        return self.waitForElement(bySelector);
    }
}

Code in util:

exports.isElementLocatedAndVisible = function isElementLocatedAndVisible(driver, bySelector) {
    return new Condition('element is located and visible', function(driver) {
        console.log(bySelector)
        return driver.findElements(bySelector).then((arr) => {
            if (arr.length > 0) {
                return arr[0].isDisplayed();
            }
            else {
                return false;
            }
        });
    });
};

I tried to use is in my test:

    this.Then(/^Tab "([^"]*)" is open$/, function (tabName) {
        this.createTab(tabName);
        //var bySelector = tab.getLocator(isActiveTab);

        return tab.tabIsOpen(tabName);
});

But I recieved an Invalid Locator error. Via debug print I see thah I miss bySelector value when code go to exports.isElementLocatedAndVisible function. This is undefiened. What I did wrong?

Upvotes: 1

Views: 1368

Answers (1)

Naveen Kumar R B
Naveen Kumar R B

Reputation: 6398

I suspect it is just missing of a parameter causing the issue.

In the following line:

return driver.wait(isElementLocatedAndVisible(bySelector), waitTimeOut);

add driver object as first argument and then bySelector, as follows:

return driver.wait(isElementLocatedAndVisible(driver, bySelector), waitTimeOut);

function is defined as follows:

function isElementLocatedAndVisible(driver, bySelector)

so, expecting driver object along with bySelector

Upvotes: 1

Related Questions