C#-如何禁用带有硒的firefox中的javascript? [英] C# - How can I disable javascript in firefox with selenium?

查看:130
本文介绍了C#-如何禁用带有硒的firefox中的javascript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码通过Specflow禁用C#Selenium Webdriver中的Java脚本.

I am using below code to disable java script in C# Selenium webdriver with specflow.

FirefoxProfile p = new FirefoxProfile();
p.SetPreference("javascript.enabled", false);
driver = new FirefoxDriver(p);

我无法为Firefox浏览器禁用javascript. 你能在我错的地方帮我吗?

I am not able disable javascript for firefox browser. Can you please help me where I am wrong.

谢谢, 索拉比(Suurabh)

Thanks, Saurabh

推荐答案

有很多建议使用FirefoxProfileDesireCapabilities来完成.这些也永远不会为我工作.出色的SO用户@alecxe给出了答案.参见

There were multiple suggestions to use FirefoxProfile or DesireCapabilities to accomplish that. Those also never work for me. What did is the answer from a brilliant SO user @alecxe. See this

幸运的是,有些人为我们做了一些伟大的工作,所以我们可以从中受益.使用插件,它将解决您的问题.并进行配置非常简单.只需右键单击添加到Firefox 按钮上,然后将链接另存为,您就可以选择保存.xpi.然后,按以下方式配置Firefox分析器.

Luckily, there are people who do some great work for us so we can take the benefit. Use this add-on and that will solve your problem. And configuring that is real simple. Just right click on the Add to Firefox button and Save link as that will give you the option to save the .xpi. Then, configure the the Firefox profiler as follows.

FirefoxProfile profile = new FirefoxProfile();
profile.AddExtension(@"D:\Users\Saifur\Desktop\noScript.xpi");
IWebDriver driver = new FirefoxDriver(profile);

driver.Navigate().GoToUrl("https://stackoverflow.com/");

而且,为了向您展示它的工作原理,我做了一个 Scrrencast

And, just to show you it's working I did a Scrrencast

这篇关于C#-如何禁用带有硒的firefox中的javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆