Hi guys
Is it possible to find out the value of a Javascript variable in the scope of the AUT? I need to build a test case that will STOP_ON_FAILURE if the Javascript variable is true.
Thanks in advance.
Russ
Hi guys
Is it possible to find out the value of a Javascript variable in the scope of the AUT? I need to build a test case that will STOP_ON_FAILURE if the Javascript variable is true.
Thanks in advance.
Russ
Bump.
Anyone?
If your Javascript function returns a variable, then you can assign it to your test variable as well:
Thanks for the link Vinh but thatâs a minefield of errors mostly because I donât understand the pure selenium environment or the Ruby answers presented.
If the answer youâre suggesting is present on that page, please point me to the actual answer AND please tell me the imports needed to use it (none of the examples explain the imports needed AFAICT). For exampleâŚ
import whatever
def myvar = runJS(âjsvarâ)
Russ
@Vinh Nguyen
Neither of these work:
def isDirty = WebUI.executeJavaScript(âisDirtyâ, null)
def isDirty = WebUI.executeJavaScript(âwindow.isDirtyâ, null)
isDirty, a boolean in JS, comes back null.
Wow. It certainly helps to RTFM 
âThe provided script fragment will be executed as the body of an anonymous function.â
def isDirty = WebUI.executeJavaScript(âreturn isDirty;â, null)
No I have my boolean!
To see it:
def isDirty = WebUI.executeJavaScript(âalert(isDirty);â, null)
Vinh, safe to close this.
Thanks.
Here is the proper method:
// +++ Imports +++
import org.openqa.selenium.WebDriver as WebDriver
import org.openqa.selenium.JavascriptExecutor as JavascriptExecutor
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory// +++ Code +++
WebDriver driver = DriverFactory.getWebDriver()
JavascriptExecutor js = ((driver) as JavascriptExecutor)
String archiveID = js.executeScript(âreturn window.archiveId;â)
print(archiveID)
Old thread but YOU are a hero - this works fantastically for attaining javascript values. THANK YOU!