Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify a JavaScript variable with Selenium

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.)

like image 747
Donald Taylor Avatar asked Jun 08 '12 16:06

Donald Taylor


1 Answers

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;");
like image 55
Petr Janeček Avatar answered Sep 23 '22 17:09

Petr Janeček