zoukankan      html  css  js  c++  java
  • nightwatch.js

    .getLocationInView()

    Determine an element's location on the screen once it has been scrolled into view. Uses elementIdLocationInViewprotocol command.

    Parameters:
    NameTypedescription
    selector string The CSS/Xpath selector used to locate the element.
    callback function Callback function which is called with the result value.
    Returns
    Typedescription
    x: number, y: number The X and Y coordinates for the element on the page.
    this.demoTest = function (browser) {
      browser.getLocationInView("#main ul li a.first", function(result) {
        this.assert.equal(typeof result, "object");
        this.assert.equal(result.status, 0);
        this.assert.equal(result.value.x, 200);
        this.assert.equal(result.value.y, 200);
      });
    };
    

     

    1down voteaccepted

    If you are using JQuery you can do it like this:

    browser.execute(function () {
        $(window).scrollTop($('some-element').offset().top - ($(window).height() / 2));
    }, []);

    Or using plain JavaScript:

    browser.execute(function () {
        document.getElementById("some-id").scrollIntoView();
    }, []);

      将屏幕滚动到底部实例:

    module.exports = {
        'your-test': function (browser) {
            browser
                .url("https://www.sohu.com/")
                .pause(1000)
                .waitForElementPresent('body', 2000, "Be sure that the page is loaded")
                .maximizeWindow()
                .pause(1000)
                .execute(function() { window.scrollBy(0, 10000000); }, []) 
                .pause(2000)
                .end();
    
        }
    }
    

      

  • 相关阅读:
    最大子序列和问题之算法优化
    数据揭秘:低学历成功逆袭概率有多少?感谢父母送我读书!
    据说这份高考卷,只有程序员能得满分!
    牛客OI赛制测试赛2
    斯特林公式
    N!的近似值_斯特林公式
    矩阵快速幂
    回文树
    回文树入门
    环和链的判断
  • 原文地址:https://www.cnblogs.com/saryli/p/7002122.html
Copyright © 2011-2022 走看看