0

Currently trying to test out the responsiveness on webdriverio. I adjust the viewport of my screen and then try to search for a table that exists at the bottom of the page (need to scroll to get into view port). For some reason, it can't locate the element and the test case fails.

it('should resize the table when screen width is mobile', () => {
    let mobileTable = $('.overview-table.mobile-table');
    browser.setViewportSize({
        width: 767,
        height: 500
    });
    //browser.pause(1500);
    mobileTable.waitForExist(10000);
    console.log(mobileTable);
    mobileTable.scroll();
    browser.debug();
});

I'm not sure if I'm getting the element right in the above code. I set mobileTable = $('.overview-table.mobile-table') because it is a table element with those classes

<table class="overview-table mobile-table"> ... </table>

I get the following error:

An element could not be located on the page using the given search parameters (".overview-table.mobile-table").
running firefox
Error: An element could not be located on the page using the given search parameters (".overview-table.mobile-table").
    at scroll() - index.js:312:3
james
  • 550
  • 8
  • 14

1 Answers1

1

The problem most likely is in your selector.

You can verify if your selector is correct by testing it into your browser javascript console. In chrome it goes like this:

  • Right click the page
  • Inspect
  • Select the "console" tab within the dev tool panel
  • Then simply type $$('.overview-table.mobile-table')

If that's an empty array, then you know the selector is wrong.

Kignuf
  • 96
  • 7
  • yeah the selector is empty. I'm trying to figure out why it's wrong? the element is ...
    how would i grab this element?
    – james Aug 30 '18 at 19:48
  • actually, no the selector is not empty. I'm at a loss now. No idea what's wrong. – james Aug 30 '18 at 20:25
  • I'm not that familiar with selenium, as I am using appium on a daily basis. If you make your test scroll down to the said element, does it work ? I know appium won't find the element unless it's visible in the viewport. Maybe that's the same on selenium. – Kignuf Aug 31 '18 at 16:36
  • it times out. As per the documentation here http://webdriver.io/api/utility/scroll.html it says to set a variable to the css selector and call the scroll function. – james Aug 31 '18 at 18:25
  • apparently the scroll command is based upon touchScroll which is deprecated ([see doc](http://webdriver.io/api/protocol/touchScroll.html)). You should [use touchPerform](http://webdriver.io/api/mobile/touchPerform.html) instead – Kignuf Sep 04 '18 at 16:14