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

      

  • 相关阅读:
    GoLang中面向对象的三大特性
    Go常用功能总结一阶段
    GO语言基础之并发concurrency
    GO语言基础之error
    GO语言基础之reflect反射
    GO语言基础之interface
    GO语言基础之method
    GO语言基础之struct
    GO语言基础map与函数
    GO语言基础条件、跳转、Array和Slice
  • 原文地址:https://www.cnblogs.com/saryli/p/7002122.html
Copyright © 2011-2022 走看看