简体   繁体   English

Webdriver:Firefox配置文件,用于动态禁用/启用JavaScript弹出窗口

[英]Webdriver: Firefox profile for disable/enable javascript popup dynamically

I am writing a test case where I have to close a java script popup. 我正在编写一个测试用例,其中必须关闭Java脚本弹出窗口。 My code works fine in windows but I am deploying the executable in a centOS based server where it is getting error like below: 我的代码在Windows中运行良好,但是我将可执行文件部署在基于centOS的服务器中,该服务器出现如下错误:

Element is not clickable at point (719, 9.899993896484375). Other element     would receive the click: <li style="display: block; bottom: 0px;" 

Can someone tell me what might be the problem? 有人可以告诉我可能是什么问题吗?

I also tried the following but it does not work. 我也尝试了以下方法,但是不起作用。

FirefoxProfile p = new FirefoxProfile();
p.setPreference("browser.popups.showPopupBlocker", false);
p.setPreference("browser.history.allowPopState", false);
p.setPreference("privacy.popups.showBrowserMessage", false);
p.setPreference("privacy.popups.usecustom", false);
driver = new FirefoxDriver(p);

I could solve the problem. 我可以解决问题。 Instead of clicking the close button of the JS popup, I removed the popup by executing javascript by injection. 我没有单击JS弹出窗口的关闭按钮,而是通过注入执行javascript删除了弹出窗口。

JavascriptExecutor jsExecutor = (JavascriptExecutor)driver;
jsExecutor.executeScript("return document.getElementsByClassName('dateInfo')[0].remove()");

Use to click using JavascriptExecutor :- 用于单击以使用JavascriptExecutor :-

WebElement element = "Your Element";
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element );

Hope it will help you :) 希望它能对您有所帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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