1
I am trying to run a function in the browser that is already set, but it is marked as undefined.
I ran the following code to reproduce the problem:
const webdriver = require("selenium-webdriver")
const driver = new webdriver.Builder().forBrowser("firefox").build()
driver.navigate().to("http://localhost/site")
driver.sleep(3000)
const code = `console.log(window.sayHello)`
const logCode = `console.log("${code}")`
driver.executeScript(logCode)
driver.executeScript(code)
When I tried to run the same code - console.log(window.sayHello) - directly in the browser still open, it returned the desired function, as in the image:
EDITED
This seems to be a specific bug with the firefox driver as Chrome worked. I believe the variable window is being superscript, but I couldn’t rewrite it with the window original.

You’re encapsulating twice, that’s what you want?
driver.executeScript(console.log("console.log(window.sayHello)"))? Won’t you want to:driver.executeScript(code);only?– Sergio
@Sergio the first line only displays the code that will be executed
– Oeslei
The
. executeScriptlog content or return? testsconsole.log('foo');, givesfooorundefined?– Sergio
@Sergio edited the question code to try to make it simpler. Basically, the first command
executeScriptonly displays the code that will run on the second call.– Oeslei