.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. 2018省赛赛第一次训练题解和ac代码

    第一次就去拉了点思维很神奇的CF题目 2018省赛赛第一次训练 # Origin Title     A CodeForces 607A Chain Reaction     B CodeForces ...

  2. CF878D D. Magic Breeding bitset

    D. Magic Breeding time limit per test 4 seconds memory limit per test 1024 megabytes input standard ...

  3. jQuery实现当按下回车键时绑定点击事件

    jQuery实现当按下回车键时绑定点击事件 <script> $(function(){ $(document).keydown(function(event){ if(event.key ...

  4. PHP允许AJAX跨域请求的两种方法

    * 一. 服务端设置 header 头允许AJAX跨域 ** 代码如下: // 允许 ityangs.net 发起的跨域请求 header("Access-Control-Allow-Ori ...

  5. 硅谷和国内的 iOS 开发到底有何不同?

    前段时间在国内各大互联网公司转了一圈.与各位 iOS 业界大佬交流了之后,深感国内变化之大,敬佩诸位国内开发者的实力和韧劲.除此之外,我还发现硅谷和国内的 iOS 开发还是差别很大,且听我慢慢道来. ...

  6. leetcode 26 水

    class Solution { public: int removeDuplicates(vector<int>& nums) { sort(nums.begin(),nums. ...

  7. 【前端学习笔记】2015-09-06 ~~~~ setAttribute()、slice()

    所遇记录: 1.setAttribute("属性",value),相同的还有addAttribute("属性名",value),getAttribute(“属性 ...

  8. PHP分页类(较完美)

    <?php /** file: page.class.php 完美分页类 Page */ class Page { private $total; //数据表中总记录数 private $lis ...

  9. d3 使用数据

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  10. 【NOIP2016】愤怒的小鸟(状压DP)

    题意: Kiana最近沉迷于一款神奇的游戏无法自拔. 简单来说,这款游戏是在一个平面上进行的. 有一架弹弓位于(0,0)处,每次Kiana可以用它向第一象限发射一只红色的小鸟,小鸟们的飞行轨迹均为形如 ...