Change JavaScript variable with Selenium

I have a JavaScript boolean with a name foothat I would like to change the value from true to false. The variable has a global scope.

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

(A variable hidden to the user disables the processor intensity, which causes Selenium to choke.)

+5
source share
1 answer

You did not specify the language and tool Selenium, therefore ...

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;");
+10
source

All Articles