0

I would like to get a value from a global variable in JavaScript:

    clearInterval(countdownTimerTHx);
    var saniye_thx = 298 // <--- This variable
    function secondPassedTHx() {

For a larger code snippet see this

Here I just want to get the value "298" in saniye_thx var

The XPATH is: //*[@id="c2VuZE9nb2xsb3dlcnNfdGlrdG9r"]/script

How can I do that? Thank you, and have a good day.

2 Answers 2

3

Assuming you have a webdriver instance driver, you should be able to use the execute_script function in order to execute client-side JavaScript to get a value.

Something like the following should show enough context to call the execute_script function and get the value.

from selenium.webdriver import Chrome

driver = Chrome()

# Setup driver to go to appropriate web site

saniye_thx = driver.execute_script('return saniye_thx')
Sign up to request clarification or add additional context in comments.

Comments

0

Try to use JavascriptExecutor

WebDriver driver = new ChromeDriver();

JavascriptExecutor je = (JavascriptExecutor)driver;

var returnValue = js.executeScript("return saniye_thx");

2 Comments

I think this concept would help achieve the goal, but the author is looking for a solution in Python.
That's right, I'm looking for a python solution, thanks anyway for your help.

Your Answer

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