Kladskull
Kladskull

Reputation: 10722

How do I get JavaScript Values from Selenium?

I am running the following code (Java selenium client)- PAGE_NUMBER has a value, but I am unable to get it using selenium:

String script = "var cellValue = selenium.browserbot.getUserWindow().PAGE_NUMBER;";
selenium.runScript(script);

String value = selenium.getEval("selenium.browserbot.getUserWindow().cellValue;");
System.out.println("Value: " + value);

Upvotes: 0

Views: 1609

Answers (1)

zpea
zpea

Reputation: 1082

I don't know Selenium 1 at all and Selenium2/Webdriver is very different. However there are three things that I suspect to play a role in this issue:

  1. Scope: You declared the variable as local to the scope of the script (by writing var). You might try using a global variable by omitting the var keyword, so that you can access it later.
  2. Why do you try to access the variable via selenium.browserbot.getUserWindow().. Try omitting this part.
  3. The semicolon after cellValue is probably no good idea either

And then again, why not simply using

String value = selenium.getEval("selenium.browserbot.getUserWindow().PAGE_NUMBER");

?

I hope at least some part of this answer helps you. As I said I am just guessing.

Upvotes: 2

Related Questions