.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. python多进程(multiprocessing)

    最近有个小课题,需要用到双进程,翻了些资料,还算圆满完成任务.记录一下~ 1.简单地双进程启动 同时的调用print1()和print2()两个打印函数,代码如下: #/usr/bin/python ...

  2. 【Luogu】P2805植物大战僵尸(拓扑排序+最大流)

    题目链接 这题数据xie强qwq.拓扑用的那个图建反了得80. 一眼看出(个屁,题解上都说一眼看出,然而我还是太蒻了)这是个最大权闭合图.从被保护植物向保护植物连边,然后跑最大流,用正点权和减去. 哦 ...

  3. kb-07线段树--11--区间多重该值多种查询

    /* lazy思想的运用,因为查询多种,如果全记录就太繁了,lazy就是如果该区间的每一个叶子的状态都相同就不用深入下去该值,只要暂时标记下,查询的时候也不用下去,直接计算: */ #include& ...

  4. 浅谈Android反调试 之 PTRACE_TRACEME

    反调试原理: 关于Ptrace:  http://www.cnblogs.com/tangr206/articles/3094358.html ptrace函数 原型为:     #include & ...

  5. Nginx+keepalived构建双主负载均衡代理服务器

    引言 Nginx是一个高性能的代理服务器,单台Nginx容易出现单点故障,使用keepalived可以实现Nginx的故障转移,保证了网站的高可用性 一.使用Nginx+keepalived的两种方案 ...

  6. scrapy之小试身手

    要爬取的网址是:http://quotes.toscrape.com/ 磕磕绊绊的写完了 spiders import scrapy from kkk.items import * class Quo ...

  7. ecs01初始化node环境

    npm install 报错 > uglifyjs-webpack-plugin@ postinstall /opt/apps/iview-admin/node_modules/webpack/ ...

  8. 关于npm run dev和npm run build的问题

    之前build打包好在我本地运行是没问题的,但是发给后端部署,他说我的路径有问题,这个是由于vue-cli默认的打包路径 的“/”根目录,由于文件没有部署到根目录所以出现了这个问题. 修改webpac ...

  9. Codevs 1010 过河卒== 洛谷 1002

     时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 如图,A 点有一个过河卒,需要走到目标 B 点.卒行走规则:可以向下.或者向右.同 ...

  10. C# 获取当前目录上一级目录

    string path="D:\AA\BB\CC"; Directory.SetCurrentDirectory(Directory.GetParent(path).FullNam ...