【问题标题】:WebDriverIO iterate through URL and scroll through eachWebDriverIO 遍历 URL 并滚动浏览每个
【发布时间】:2020-10-08 00:28:11
【问题描述】:

我正在使用 WebDriverIO (v5.18.7),我正在尝试编写一些可以转到每个 URL 的内容,并逐步向下滚动直到到达底部,然后继续下一个 URL。我遇到的问题是,当涉及到脚本的滚动部分时,它可能会在转到下一个 URL 之前滚动一次。

据我了解,WebDriverIO 的文档说命令是异步发送的,这是在后台框架中处理的。所以我尝试坚持使用框架并尝试 browser.execute / browser.executeAsync 但无法使其正常工作。

这就是我所拥有的,似乎接近我想要的。任何指导将不胜感激!

const { doesNotMatch } = require('assert');
const assert = require('assert');
const { Driver } = require('selenium-webdriver/chrome');

// variable for list of URLS
const arr = browser.config.urls

describe('Getting URL and scrolling', () => {
  it('Get URL and scroll', async () => { 
    // let i = 0;
    for (const value of arr) {
      await browser.url(value);
      await browser.execute(() => {
      const elem = document.querySelector('.info-section');
        // scroll until this reaches the end. 
        // add another for loop with a counter?
        elem.scrollIntoView(); //Using this for now as a place holder
      });
      // i += 1;
    } 
  })
})

【问题讨论】:

    标签: javascript webdriver-io


    【解决方案1】:

    简短回答$('.info-section').scrollIntoView()

    https://webdriver.io/docs/api/element/scrollIntoView.html

    WebdriverIO 支持同步和异步模式,见https://webdriver.io/docs/sync-vs-async.html

    【讨论】:

      猜你喜欢
      • 2020-05-15
      • 2023-03-16
      • 1970-01-01
      • 2022-01-05
      • 2017-09-01
      • 2013-01-27
      • 1970-01-01
      • 1970-01-01
      • 2020-10-08
      相关资源
      最近更新 更多