Cannot hide changing element using JQuery

巧了我就是萌 提交于 2021-02-11 13:41:19

问题


Complete JQuery newbie here, so apologies if I'm missing something blatantly obvious! :) As part of my nightwatchjs test script, I'm using JQuery to try and stop a Cookie Policy window from displaying.

The Cookie Policy window ID is displayed as either;

div[id=sp_message_container_156527]

or

div[id=sp_message_container_156525]

which of these is displayed is completely random, supplied by a 3rd party.

So I thought I'd use JQuery to try and 'hide' this element from appearing when the page is loaded (which makes my further commands in my script infinitely easier to run) using the following in my nightwatchjs test script;

const { JSDOM } = require( 'jsdom' );
const { window } = new JSDOM( '' );
const $ = require( 'jquery' )( window );

exports.command = function() {
    this.pause(5000);
    $('div[id*=sp_message_container]').hide();
    this.pause(3000);
};

However, this does not appear to work, as the element is still being displayed.

Am I doing something obviously wrong here?

Thanks.

来源:https://stackoverflow.com/questions/62592170/cannot-hide-changing-element-using-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!