Home > Software engineering >  Adding a variable to a link name/add variable to parameter
Adding a variable to a link name/add variable to parameter

Time:10-11

I am trying to open a wolfram alpha window with a query at the end like this:

sample = 5
driver.execute_script("window.open('http://www.wolframalpha.com/input/i?='   sample);")

However it is giving me error:

raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.JavascriptException: Message: A JavaScript exception occured: Can't find variable: sample

Please someone tell me how to add a variable and open a new window with it!

CodePudding user response:

What you probably want to do is open a window with the sample variable from your script being an argument of the url.

Like this:

sample = 5
url = "http://www.wolframalpha.com/input/?i={}".format(sample)  # sample is a variable
script = "window.open('{}');".format(url)
driver.execute_script(script)
  • Related