如何在使用Selenium时禁用Javascript? [英] How to disable Javascript when using Selenium?

查看:2322
本文介绍了如何在使用Selenium时禁用Javascript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在使用selenium时禁用javascript,以便我可以测试服务器端验证。

I am wondering how do I disable javascript when using selenium so I can test server side validation.

我发现这篇文章但我不知道该怎么做做。就像我制作这个javascript文件然后呢?

I found this article but I don't know what to really do. Like I make this javascript file then what?

http://thom.org.uk/2006/03/12/disabling-javascript-from-selenium/

推荐答案

编辑



在此期间确实出现了更好的替代方案,请参阅其他答案,例如 https://stackoverflow.com/a/7492504/47573

其他可能性为:


  • 编写申请支持禁用JavaScript(是的, web 应用程序)。
    听起来很疯狂?不是。在我们的开发过程中,我们正是这样做的,在没有JS的情况下实现功能,直到所有功能都在那里,然后用JS调整。我们通常在所有模板中提供一个钩子,它可以从单个点控制到基本上从Web应用程序本身关闭/打开的JS。并且,是的,如果没有启用JS,应用程序很难识别,但这是确保工作正常运行的最佳方法。对于这两个版本,我们甚至为它编写Selenium测试; NOJS和JS。 NOJS如此快速地实现,与编写复杂的JS测试相比无关紧要......

  • 修改相应的浏览器配置文件以禁用JS。即对于FF,您可以告诉Selenium使用哪个配置文件;您可以正常加载此配置文件,在about:config中禁用JS并将此配置文件作为默认配置文件提供给Selenium RC。

  • Write your application to support disabling JavaScript (yes, the web application).
    Sounds crazy? Isn't. In our development process we're doing exactly this, implementing features without JS until all are there, then spice up with JS. We usually provide a hook within all templates which can control from a single point to basically which JS off/on from the web application itself. And, yes, the application is hardly recognizable without JS enabled, but it's the best way to ensure things work properly. We even write Selenium tests for it, for both versions; NOJS and JS. The NOJS are so quickly implemented that they don't matter compared to what it takes to write sophisticated JS tests ...
  • Modify the appropriate browser profile to have JS disabled. I.e. for FF you can tell Selenium which profile to use; you can load this profile normally, disable JS in about:config and feed this profile as default profile to Selenium RC.

这篇关于如何在使用Selenium时禁用Javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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