0

I am triggering a modal on Swagger UI page load then setting the value of input field of Bearer token and then wish to click on the 'Authorize' button programmatically to close the bearer token modal(Screenshot below).But the button seems disabled and unless I manually type something in the input it does not get enabled.What could be the issue?

   window.addEventListener('load', function() {
    
        // On Load triggers Modal Popup
        const authorizeButton = document.getElementsByClassName('authorize')[0];
        authorizeButton.click();
    
        //Set Input Field
        const abcd = document.querySelectorAll('[aria-label="auth-bearer-value"]');
        abcd[0].value = 'abcd';
    
        abcd[0].dispatchEvent(new Event('change'));
        abcd[0].dispatchEvent(new Event('keydown'));
        abcd[0].dispatchEvent(new Event('keypress'));
        abcd[0].dispatchEvent(new Event('keyup'));
        abcd[0].dispatchEvent(new Event('input'));


       // Need to Click on 'Authorize' button as shown in screenshot but it seems to be disabled
}

enter image description here

Teknoville
  • 459
  • 1
  • 7
  • 18
  • Check [this answer](https://stackoverflow.com/a/2856602/17264570). Set the input value but fire the `onchange` event since probably swaggerui is listening to it instead of watching the input's value – eroironico Dec 07 '22 at 08:35
  • @Nick I did try that but it does not seem to be working.I updated the code as well – Teknoville Dec 07 '22 at 08:57
  • I don't know how swaggerui works, however try inspecting their page and use `getEventListeners()` to find which element is listening to which event – eroironico Dec 07 '22 at 09:18

0 Answers0