I'm doing some selenium web testing and on this one site I'm automating a modal popup would sometimes show up randomly and would prevent me from grabbing other elements. I know there are built in Selenium methods for closing the popup like alert().dismiss() but this would mean I know when the popup would show up and I don't it shows up at random.
我正在进行一些硒网测试,在这个网站上,我自动化模式弹出窗口有时会随机出现,会阻止我抓住其他元素。我知道有一些Selenium方法用于关闭弹出窗口,如alert()。dismiss(),但这意味着我知道弹出窗口何时出现,我不会随机出现。
I would like to know how to attach an event listener for when these modal popups show up and have a callback that would close out of it. please and thanks
我想知道如何附加一个事件监听器,以便在这些模态弹出窗口显示并有一个可以关闭它的回调时。拜托,谢谢
1 个解决方案
#1
0
If you know where is the code that triggers the popup, you can simply inject few line of javascript in webdriver and nullify the popup.
如果您知道触发弹出窗口的代码在哪里,您只需在webdriver中注入几行javascript并使弹出窗口无效。
As an example, if the popup appears after a couple of seconds and is triggered by the following code:
例如,如果弹出窗口在几秒钟后出现并由以下代码触发:
setTimeout(function () { showModal() }, 5000);
setTimeout(function(){showModal()},5000);
you could override the modal function in the webpage with the following (Java) code:
您可以使用以下(Java)代码覆盖网页中的模态函数:
driver.executeScript("showModal = function () {}");
driver.executeScript(“showModal = function(){}”);
the next time the modal is executed this will trigger an empty function.
下次执行模态时,这将触发一个空函数。
#1
0
If you know where is the code that triggers the popup, you can simply inject few line of javascript in webdriver and nullify the popup.
如果您知道触发弹出窗口的代码在哪里,您只需在webdriver中注入几行javascript并使弹出窗口无效。
As an example, if the popup appears after a couple of seconds and is triggered by the following code:
例如,如果弹出窗口在几秒钟后出现并由以下代码触发:
setTimeout(function () { showModal() }, 5000);
setTimeout(function(){showModal()},5000);
you could override the modal function in the webpage with the following (Java) code:
您可以使用以下(Java)代码覆盖网页中的模态函数:
driver.executeScript("showModal = function () {}");
driver.executeScript(“showModal = function(){}”);
the next time the modal is executed this will trigger an empty function.
下次执行模态时,这将触发一个空函数。