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();
    
        }
    }
    

      

  • 相关阅读:
    acm python
    html cheatsheet
    unix cheatsheet
    liunx dd 读取系统文件
    比较文件内容是否相同
    linunx siege 安装
    数据库备份并压缩
    innobackupex xtrabackup 备份恢复mysql数据
    ubuntu安装rally
    解决Ubuntu显示中文乱码的问题
  • 原文地址:https://www.cnblogs.com/saryli/p/7002122.html
Copyright © 2011-2022 走看看