Forum Discussion

ManRam2020's avatar
New Contributor
5 years ago

Automating Oauth2 token retrieval- 'Implicit Grant' method . Java script in auth manager failing

We are trying to automate the OAuth2 Azure token retrieval and we use Implicit grant method. 


In the java script to automate the login UI page , we dont have id's , had to use the Xpath, so replaced the ids with xpaths, used the findchildbyXpath method, a compilation error is thrown saying FindbychildXpath is not available, so tried importing the package, when done, it throws script missing ; error. It is not liking any import statements there. So, not sure what is missing. Could someone please throw some ideas ? I am following the documentation in SmartBear -


Also, followed the recommendations in the community discussion,


This is the javascript i am using, 


import javax.xml.xpath.XPathExpression ;

// This function asks for permission to use OAuth. The user must be logged in to use it. Logging in is performed in the script below.
function consent() {
if (document.FindChildByXpath('//*[@id="i0281"]/div/div/div[1]/div[3]/div/div/div')){

// This function fills user password in when the user name is already known. It uses the project-level "pass" property.
function fillpwd() {
document.FindChildByXpath('//*[@id="i0281"]/div/div/div[1]/div[3]/div/div[2]').value = 'xxxxxxx';
window.setInterval(consent, 100);

// This script checks what page is displayed and provides the appropriate data. It uses the project-level "user" and "pass" properties.
if (document.FindChildByXpath('//*[@id="i0281"]/div/div/div[1]/div[3]/div/div/div') && document.getElementByXpath('//*[@id="loginHeader"]/div')) {
document.FindChildByXpath('//*[@id="tilesHolder"]/div[1]/div/div').value = 'xxxxxx';
window.setTimeout(fillpwd, 100);
} else if (document.FindChildByXpath('//*[@id="i0281"]/div/div/div[1]/div[3]/div/div[2]')) {
// Thread.Sleep(3500);
} else if(document.FindChildByXpath('//*[@id="i0281"]/div/div/div[1]/div[3]/div/div/div')){
window.setInterval(consent, 100);

2 Replies

    • ManRam2020's avatar
      New Contributor

      Thank you so much for the response on this , Natalie, i tried using  evaluate() method per your recommendation, it throws errors saying two arguments needs to be passed.

      TypeError: Failed to execute 'evaluate' on 'Document': 2 arguments required, but only 1 present.Uncaught TypeError: Failed to execute 'evaluate' on 'Document': 2 arguments required, but only 1 present.Uncaught TypeError: Failed to execute 'evaluate' on 'Document': 2 arguments required, but only 1 present.Uncaught


      Also, our UI is defaulted to go through IE, in the link shared, it says, evaluate method is not supported for IE.

      Am i missing something ? I am pretty new to API automation. 


      Thanks in advance.