简体   繁体   English

滚动页面 selenium webdriver JS

[英]scroll page selenium webdriver JS

I am trying to test on selenium webdriver JS.我正在尝试在 selenium webdriver JS 上进行测试。 I have functions that look for an element on the site.我有在网站上寻找元素的功能。

 createAccount() {
        return this.driver.findElement(By.css(".button"));
    }

There is a function that scrolls the page to the desired item.有一个 function 可以将页面滚动到所需的项目。 I want to scroll through the function, pass the search function as an argument.我想滚动浏览 function,将搜索 function 作为参数传递。

scrollToElement(el) {
        this.driver.manage().window().maximize();
         return  this.driver.executeScript('arguments[0].scrollIntoView(true);', el );
    }

The test runs in a separate file.测试在单独的文件中运行。

 async main() {
    const page = this.Page;
    page.open();
    page.scrollToElement(createAccount);
    await page.createAccount().click();
}

And when I run it, an error appears:当我运行它时,会出现一个错误:

UnhandledPromiseRejectionWarning: JavascriptError: javascript error: Cannot read property 'scrollToElement' of null UnhandledPromiseRejectionWarning:JavascriptError:javascript 错误:无法读取 null 的属性“scrollToElement”

Looks like it cannot find the createAccount element.看起来它找不到createAccount元素。 Try finding the element using the id or by xpath .尝试使用idxpath查找元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM