简体   繁体   中英

WebDriverIO iterate through URL and scroll through each

I'm using WebDriverIO (v5.18.7) and I'm trying to write something the can go to each URL, and scroll down in increments until you reached the bottom, then move on the next URL. The issue I'm having is when it comes to the scrolling portion of the script, it might scroll once before it goes to the next URL.

From what I'm understanding, the documentation for WebDriverIO says the commands are send in asynchronous, which is handled in the framework behind the scenes. So I tried sticking with the framework and tried browser.execute / browser.executeAsync but wasn't able to get it working.

Here's what I have that seems close to what I want. Any guidance would be appreciated!

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;
    } 
  })
})

Short anwer $('.info-section').scrollIntoView()

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

WebdriverIO suppors sync and async modes, see https://webdriver.io/docs/sync-vs-async.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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