.getLocationInView()

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

Parameters:
Name Type description
selector string The CSS/Xpath selector used to locate the element.
callback function Callback function which is called with the result value.
Returns
Type description
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(); }
}

  

nightwatch.js - scroll until element is visible的更多相关文章

  1. Nightwatch.js – 轻松实现浏览器的自动测试

    Nightwatch.js 是一个易于使用的,基于 Node.js 平台的浏览器自动化测试解决方案.它使用强大的 Selenium WebDriver API 来在 DOM 元素上执行命令和断言. 语 ...

  2. 两个标签页定位第二个标签页元素时显示element not visible

    问题描述 web页面有两个标签页, 当转换到第二个标签页定位元素时, 显示element not visible. 代码 ... //省略 WebElement ele= browser.getEle ...

  3. ElementNotVisibleException: Message: element not visible

    selenium自动化测试中,经常会报异常: 可能会有各种疑问,元素可以定位到啊.为什么报以下异常? ElementNotVisibleException: Message: element not ...

  4. selenium.common.exceptions.ElementNotVisibleException: Message: element not visible处理方法:selenium针对下拉菜单事件的处理

    使用Selenium爬虫时,可能会遇到一些下拉菜单,动态加载,如果直接使用find_element_by_函数会报错,显示selenium.common.exceptions.ElementNotVi ...

  5. 爬虫-Selenium -抱错ElementNotVisibleException: Message: element not visible

    1.当使用Selenium IDE 完成了脚本的录制和回放通过后,想要将脚本转换为其他语言如java.Python等,首次使用时打开Options->Format发现没有可以转换的语言,如下: ...

  6. 使用Nightwatch.js做基于浏览器的web应用自动测试

    1        安装 1.1   安装Node.js 在http://nodejs.org/ 上下载适合本机系统的安装包运行安装,注意安装选项中选择npm tool以用于后续依赖包的安装. 1.2  ...

  7. element not visible的解决方法

    抛出异常主题为element not visible主要有一下三个方面的原因. 元素之间存在逻辑关系,比如你要选择地址时,中国选择完毕之后,才能选择北京.如果想直接一步到位,则会出现element n ...

  8. switchable css dark theme in js & html custom element

    switchable css dark theme in js & html custom element dark theme / dark mode https://codepen.io/ ...

  9. Laravel 6.X + Vue.js 2.X + Element UI +vue-router 配置

    Laravel 版本:6.X Vue 版本:2.X Laravel配置: Laravel使用的是Laragon安装 选择Laravel:接下来弹出框,输入项目名,laravel会自动创建一个数据库,数 ...

随机推荐

  1. leetcode 20 简单括号匹配

    栈的运用 class Solution { public: bool isValid(string s) { stack<char>The_Stack; ; The_Stack.push( ...

  2. Cannot open include file: 'initializer_list': No such file or directory

    Cannot open include file: 'initializer_list': No such file or directory今天使用VS2012编译一个项目的时候,遇到了这个问题,上 ...

  3. centons7编译安装zabbix3.4【转https://www.cnblogs.com/kowloon/p/7771495.html】

    或者参考官方文档:https://www.zabbix.com/documentation/3.4/manual/installation/install 一.预编译环境准备 1.lamp安装和启动 ...

  4. Process类,Thread类,Pool类,gevent类,ProcessPoolExecutor,ThreadPoolExecutor的用法比较

    一 Process类 multiprocessing模块下的一个类 创建子进程. 有两种方法 方法一 from multiprocessing import Process import os def ...

  5. 超爽的Windows终端Cmder

    我们常常看到科研.军事.编程上用的计算机系统是"黑洞洞"的,没有桌面.相对我们现在使用的Windows系统,既方便又美观,那么他们怎么不用Windows一样的图形化界面呢? 告诉你 ...

  6. bzoj 3060[Poi2012]Tour de Byteotia 贪心+生成树

    Description 给定一个n个点m条边的无向图,问最少删掉多少条边能使得编号小于等于k的点都不在环上. Analysis 包含关键点的环中 包含从关键点连出的两条边 考虑我们删边删哪些边更优 根 ...

  7. poj 4001 To Miss Our Children Time

    To Miss Our Children Time Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Jav ...

  8. SharePoint 2013 Custom MasterPage

    <%@Master language="C#"%> <%@ Register Tagprefix="SharePoint" Namespace ...

  9. linux内核栈与用户栈【转】

    转自:http://19880512.blog.51cto.com/936364/274610 最近linux内核的中断部分,总是被书里的栈弄晕,一会儿内核栈,一会儿用户栈的……很是崩溃,在网上goo ...

  10. 从网上搜集的X86 显示 int 10H

    INT 10H 是由 BIOS 对屏幕及显示器所提供的服务程序,而后倚天公司针对倚天中文提供了许多服务程序,这些服务程序也加挂在 INT 10H 内.使用 INT 10H 中断服务程序时,先指定 AH ...