javascript - nightwatch.js - scroll until element is visible -
i want scroll page until desired element appear visible.
i have tried:
browser.execute(function () { window.scrollby(0, 10000000); }, []);
and
browser.getlocationinview("<selector>", function(result) { this.assert.equal(typeof result, "object"); this.assert.equal(result.status, 0); this.assert.equal(result.value.x, 200); this.assert.equal(result.value.y, 200); });
first not scroll page , second fails because element not visible.
how fix this? want scroll till element appear visible.
if using jquery can this:
browser.execute(function () { $(window).scrolltop($('some-element').offset().top - ($(window).height() / 2)); }, []);
or using plain javascript:
browser.execute(function () { document.getelementbyid("some-id").scrollintoview(); }, []);
also, in cases suggest use nightwatch's waitforelementvisible instead of assertions because when using assertions check @ given moment if element visible using waitforelementvisible
can specify how long wait visible.
if element hidden might not visible before assertion run causes assertion fail though element visible.
Comments
Post a Comment