• Forums
    • Public Forums
      • Community Connect
      • Dynatrace
        • Dynatrace Open Q&A
      • Application Monitoring & UEM
        • AppMon & UEM Open Q&A
      • Network Application Monitoring
        • NAM Open Q&A
        • Enterprise Synthetic Monitoring
      • Synthetic Classic
        • Synthetic Classic Open Q&A
  • Home /
  • Public Forums /
  • Synthetic Classic /
  • Synthetic Classic Open Q&A /
avatar image
Question by Adam G. · Aug 17, 2016 at 12:41 PM · scripting custom action custom code

Validate that Javascript variable present in source code

Hi all,

Is it possible to fail a script if a javascript variable is not present in the source code of a page? How would this be done?

<html>
<head>
<title>My Page</title>
<script>
var myVar = Math.random() + "";
</script>
</head>
<body>...</body>
</html>

Assuming the above page, how would I check that myVar exists & if it doesn't, fail the script.

I've tried this example, this example, window.myVar, gomez_top[0].myVar with no joy.

I will fail the script using this method.

Comment

People who like this

0 Show 0
10 |2000000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 10 attachments (including images) can be used with a maximum of 52.4 MB each and 262.1 MB total.

1 Reply

  • Sort: 
  • Most voted
  • Newest
  • Oldest
avatar image

Answer by Brett B. · Aug 17, 2016 at 12:55 PM

Hey Adam,

Could you write a try/catch block around the line where you use the variable? Something like:

try{
	myVar = Math.random() + "";
}
catch(err){
	log(err.message)
}

I saw this w3schools example which changed the doc.innerHTML on a var not being set

Comment

People who like this

0 Show 0 · Share
10 |2000000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 10 attachments (including images) can be used with a maximum of 52.4 MB each and 262.1 MB total.

Join the conversation!

First steps in the forum
Community User Guide

LIVE WEBINAR

"Power Demo: Software Intelligence for Cloud Infrastructure"


DECEMBER 12, 10:00 AM GMT / 2:00 PM ET

Register here

Live webinar: Ensuring Digital Business Availability with Dynatrace

Learn how Dynatrace Real User Monitoring automatically detects errors that impact your end users caused by erroneous 3rd party or CDNs.
December 10, 4:00 pm CET / 10:00 am ET
Register here

Live webinar: Ensuring Digital Business Availability with Dynatrace

Learn how Dynatrace Real User Monitoring automatically detects errors that impact your end users caused by erroneous 3rd party or CDNs.
December 10, 4:00 pm CET / 10:00 am ET
Register here

Live webinar: Ensuring Digital Business Availability with Dynatrace

Learn how Dynatrace Real User Monitoring automatically detects errors that impact your end users caused by erroneous 3rd party or CDNs.
December 10, 4:00 pm CET / 10:00 am ET
Register here

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Way to extend Token manipulation to desktop Scripts 1 Answer

new dynatrace synthetic custom scripting guide 1 Answer

Is there a way to close a browser tab? 1 Answer

Conditional script fails with: Locator is not defined 1 Answer

Step 5, action 4: gomez_control.setVar is not a function 1 Answer

Forum Tags

configuration summary mobile monitoring tests timeout synthetic monitoring reports flash synthetic mobile guardian synthetic percentile test management w3c web recorder rest api errors dashboard waterfall chart 2017-Q2 release number login retry on error synthetic monitoring private peer monitoring firefox flex sliverlight dynatrace advanced synthetic account windows recorder last mile monitoring interactive charting webinar gomez 2014-Q3-SEP dynatrace recorder speed index high five award backbone load testing community awards ftp chrome private last mile benchmark leapsecond web performance monitoring sms alerts scoe news synthetic sla report portal alerting performance monitoring web services notifications native mobile app reports third party apr-2017 setup tests browser agent april-2017 chart cloud wait perspective report threshold certificate appmon scripting custom action recorder agent custom code https emails
  • Forums
  • Public Forums
    • Community Connect
    • Dynatrace
      • Dynatrace Open Q&A
    • Application Monitoring & UEM
      • AppMon & UEM Open Q&A
    • Network Application Monitoring
      • NAM Open Q&A
      • Enterprise Synthetic Monitoring
    • Synthetic Classic
      • Synthetic Classic Open Q&A