clicking button using executescript in protractor

2019-07-31 23:34发布

问题:

I have to click a button and since it is not clicking directly, i am using the below code and it is working.

var create = element(by.css('button[title="Add Master Obligation"]'))
browser.executeScript("arguments[0].scrollIntoView();arguments[1].click();", create, create);

I want to put the same for page object model in protractor. So, i have added like this. page.ts:

var mo = function () {

    this.createbutton = function () { 
        var create = element(by.css('button[title="Add Master Obligation"]'))
        browser.executeScript("arguments[0].scrollIntoView();arguments[1].click();", create, create);   
    }

If I call this in my spec, like below

var mo = require("../page/mo.ts")

    it('create  master obligation', function () {
        browser.sleep(10000);
mo.createbutton;
    })

it is not clicking the button. How to resolve this issue?