5

I have a boolean JavaScript variable named foo that I would like to change the value of from true to false. The variable has global scope.

In Selenium, how can I change the value of this variable?

(The variable, hidden to the user, disables a CPU-intensive feature that causes Selenium to choke.)

1 Answer 1

14

You didn't specify a language and Selenium tool, so...

Java + Selenium WebDriver

// assuming JS is enabled for this driver instance
((JavascriptExecutor)driver).executeScript("window.foo = false;");

Java + Selenium RC

selenium.getEval("window.foo = false;")

C# + Selenium WebDriver

((IJavaScriptExecutor)driver).ExecuteScript("window.foo = false;");
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. The language I'm using for Selenium is Java.
for Python also, please. I am using Python + Webdriver

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.