Question

Web Automation Package - ServiceNow Click or Execute Javascript

  • 8 November 2022
  • 3 replies
  • 40 views

Userlevel 2
Badge +4

Case 01922755

 

@Ravi Shankar​ 

 

I am trying to automate click interactions with the ServiceNow application using the web automation package. I have watched a number of videos regarding this package and have tried the following different options with no success.

 

  1. Tried using the recorder (this was not using Web Automation Package but was unsuccessful as the objects did not list all of the properties and I could not get the click interactions to work)
  2. Tried using Web Automation: Click > Search By Element Xpath > Click
  3. Tried using Web Automation: Click> Search By Element ID > Click
  4. Tried using Web Automation: Click > Search By Tag Name > Click
  5. Tried using Web Automation: Click > Search (Javascript) > Click
  6. Tried using Web Automation: Execute Javascript > Variable
  • Tried using document.querySelector()
    • Tried using document.querySelectorAll()
    • Tried using document.getElementByID
    • Tried using document.getElementsByName

 

The two options below have been the most successful in tests.... however I am getting inconsistent results…..I believe this has to do with the state of the website. i.e. if I fiddle around in the google developer tools console and click a few times on the screen sometimes the javascript commands will work. I have noticed a lot of times when they work there is a message in the console that says "dirty form focus"… However, when I use them in the Automation Anywhere Control Room they never do?

 

  1. Tried using document.getElementById('sys_original.x_eyit2_dsr_dsr_task.dsr_case').value
  • This returns a unique sys_ID that I can use as follows
  1. BaseURL + sysID to navigate where I want….but the webpage behavior is inconsistent
  • Sometimes when I type this in the google developer tools console it will work and other times it will not
    • When it works I notice in the console that before it works it says "dirty form focus"

 

Attaching a few images of the google developer tools console to get the unique sys_id....ServiceNowAttribute 

ServiceNowJSInconsistent 

  1. Tried using document.getElementById('x_eyit2_dsr_dsr_task.number').click()
  • This will click the button properly however it is inconsistent as I have mentioned above. It seems to work intermittently in the google developer tools when I fiddle around with the website or use google developer tools > inspect element but has never worked when I run it in the Automation Anywhere Control Room

 

See Below Unsuccessful click.... However if I fiddle around with the website or use google developer tools > inspect element....sometimes it will work in the console (It has never worked in Automation Anywhere Control Room...)

 

ServiceNowJSClick 

Build number – 4.0.0-beta-2, revision 4ec0cfc112

Environment - (Prod/Dev/UAT/Staging etc.)UAT

Deployment - (On-Prem/Cloud)Cloud

Operating System Used - (Win10/Server & Enterprise/Professional)Windows 10 Enterprise 10.0.19044 Build 19044

Bot Agent Version – 21.222

 


3 replies

Badge +4

@Matt Mickle​ 

Most probably, you are not targeting the correct iframe?  Developer tools > inspect element > highlighting element is auto selecting correct frame for console and works ?

 

You could also use Servicenow REST API to get data/ automate.

Userlevel 2
Badge +4

@Sumit Kumar​ 

 

"Developer tools > inspect element > highlighting element is auto selecting correct frame for console and works ?'

 

No this does not work.... What I meant is if I type the below javascript into the google developer tools console once the page loads:

 

document.getElementById('sys_original.x_eyit2_dsr_dsr_task.dsr_case').value

 

It will not work.....

 

However, after this initial command does not work if I click a few places on the page or if I do this:

 

Developer tools > inspect element > highlighting element

 

and then go back to the console and type the same javascript into the console.... the same exact Javascript will now return me the correct result:

 

document.getElementById('sys_original.x_eyit2_dsr_dsr_task.dsr_case').value

 

This is what I mean by the website being inconsistent.

 

Can you please provide more information on the Servicenow REST API and how to use it in practice?

Userlevel 2
Badge +4

Does anyone have any insight into how to get web automation to work properly based on the above scenario? I see the web automation package specifically mentions service now in the description. I feel like I'm definitely barking up the right tree, but I need some guidance....

 

Any help would be much appreciated.

Reply