小编cmp*_*ore的帖子

使用Selenium在Python中滚动到页面顶部

我在使用Python和Selenium时遇到滚动到网页顶部的问题.

当页面由于某种原因加载时,您将被带到页面底部(这是由于修复).但是,当我试图滚动到顶部时,它不起作用.

我尝试了以下方法:

self.driver.execute_script("scroll(0, -250);")
Run Code Online (Sandbox Code Playgroud)

self.driver.execute_script("scroll(0, 0);")
Run Code Online (Sandbox Code Playgroud)

我也试过找到元素然后滚动到它:

self.driver.execute_script("arguments[0].scrollIntoView()", element)
Run Code Online (Sandbox Code Playgroud)

向上滚动到元素时,上面的scrollIntoView()代码可以正常工作.但是,它不能向上滚动.

我试过这个运行Chrome驱动程序和PhantomJs.

有什么建议?

javascript python selenium webdriver selenium-webdriver

10
推荐指数
2
解决办法
1万
查看次数

错误:在量角器中无法找到模块

所以我是新的量角器并尝试使用页面对象进行测试,以使代码更易于管理.在这方面遇到一些问题.

下面是我的主要spec文件'example_spec.js'

describe('angularjs homepage', function() {

  var home_page = require('../home_page.js');

  it('should greet the named user', function() {
    home_page.enterFieldValue('Jack Sparrow');
    var getHomePageText = home_page.getDyanmaicText();
    expect(getHomePageText).toBe('Hello Steve!');
  });
});
Run Code Online (Sandbox Code Playgroud)

下一个文件是名为"home_page.js"的页面对象

var home_page = function(){

    //Send in a value.
    this.enterFieldValue = function(value){
        element(by.model('youName')).sendKeys(value);
    };

    this.getDyanmaicText = function(){
      return element(by.binding('yourName')).getText();

    };

};

module.exports = new home_page();
Run Code Online (Sandbox Code Playgroud)

问题是在运行此测试时我得到以下错误.即使为文件尝试不同的路径,我仍然会收到错误.任何帮助,将不胜感激.

Failures:
1) angularjs homepage encountered a declaration exception
  Message:
    Error: Cannot find module '../home_page.js'
  Stack:
    Error: Cannot find module '../home_page.js'
        at Function.Module._resolveFilename (module.js:455:15)
        at Function.Module._load (module.js:403:25)
        at …
Run Code Online (Sandbox Code Playgroud)

javascript testing requirejs pageobjects protractor

3
推荐指数
1
解决办法
6894
查看次数