dave
dave

Reputation: 683

Can Selenium web driver have access to javascript global variables?

Hi: I'm writing tests for django with javascript and I was wondering if the Selenium webdriver can access a javascript global variable. mypage has a script that has a global variable I'd like to access. Is it possible? Thanks!

from django.test import LiveServerTestCase
from selenium.webdriver.firefox.webdriver import WebDriver

class TestEditorSelenium(LiveServerTestCase):
    def setUp(self):
        self.driver = WebDriver()

    def test_mytest(self):
        self.driver.get('%s%s' % (self.live_server_url, '/mypage/'))

Upvotes: 13

Views: 17879

Answers (1)

Scott
Scott

Reputation: 9488

Yes, you should be able to that with code similar to the below:

browser.execute_script("return globalVar;")

Upvotes: 27

Related Questions