To trigger an API call, I’m trying to execute fetch command through browser console using JAVA/Selenium (As it is internal site, I’m using this approach)
But the fetch statement is just printed on the console and not executed.
If I manually run the same fetch command (copy, paste and enter in console), I’m able to see the API call triggered under networks tab and Promise is created in console
JAVA Program:
driver.get(https://webadmin);
WebDriverWait wait = new WebDriverWait (driver, 20);
wait.until(ExpectedConditions.VisibilityofElementLocated(By.xpath("//input[@value='Save UserName']")));
String myStr = “fetch(https://webadmin/api/User/GenerateCODE, {“ +
“”header”: {“ +
“accept”: ”application/json, text/plain, */*”,” +
.
.
.
”token”: ”x12xdjseuhfoscoan23ffcnenamJUIncenaicnao” +
},” +
”referrer”: ”https://webadmin/api/User/Search,” +
”body”: ”{”unm”: ”myname”}”,” +
”method”: ”POST”,” +
“});””;
JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
jsExecutor.executeScript(myStr);
Thread.sleep(1000);