简体   繁体   English

使用C#和Selenium WebDriver在呈现页面中禁用Chrome中的JavaScript

[英]Disable JavaScript in Chrome with rendered page with C# & Selenium WebDriver

I am running my test in Visual Studio 10, with C# and Selenium. 我正在使用C#和Selenium在Visual Studio 10中运行测试。 There is a moment that Im landing on a page and I need to check some elements of the page, but its like "loading" continuously so its impossible to find this elements, cause are changing. 我有一段时间要登陆页面,我需要检查页面的某些元素,但是它就像不断地“加载”一样,因此找不到此元素的原因正在改变。 The only way to find them is in Chrome Settings, Disable JavaScript and perfect it works. 找到它们的唯一方法是在Chrome设置中,禁用JavaScript并使其完美运行。 But how I disable Javascript with selenium in the same page, without call a new one? 但是,如何在同一页面中禁用带有硒的Javascript,而不调用新页面呢? Just refreshing or smthg. 只是令人耳目一新或smthg。 Thx!!! 谢谢!!!

ElBandido ElBandido

You can set that to profiler. 您可以将其设置为事件探查器。 Handling would be different based on how you want to do it 根据您的操作方式,处理方式会有所不同

var firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("javascript.enabled", false);

See this 看到这个

For Chrome 对于Chrome

DesiredCapabilities caps = DesiredCapabilities.chrome();
caps.setCapability("chrome.switches", Arrays.asList("--disable-javascript"));

Taken from here 这里取

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

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