0

I used JavascriptExecutor instead of sendkeys to type the text in the username textbox.It types the text but shows the below exception in the console.

I have tried on Chrome version 74 with the latest standalone server.

 System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
            WebDriver driver=new ChromeDriver();
            driver.get("https://www.apsrtconline.in/oprs-web/login/show.do");
            driver.manage().window().maximize();
            driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
            WebElement ele=driver.findElement(By.name("userName"));
            JavascriptExecutor jse=(JavascriptExecutor) driver;
            jse.executeAsyncScript("arguments[0].value='Vinutha'", ele);
            driver.findElement(By.id("submitBtn")).click();

I expect the test to be passed.But there is a script timeout exception .

Exception in thread "main" org.openqa.selenium.ScriptTimeoutException: script timeout: result was not received in 30 seconds at the line jse.executeAsyncScript("arguments[0].value='Vinutha'", ele);

1 Answer 1

1

Use jse.executeScript instead or jse.executeAsyncScript. I believe the executeAsyncScript is used in case of multiple threads. (As per my understanding from reading java doc) ..... Execute an asynchronous piece of JavaScript in the context of the currently selected frame orwindow. Unlike executing synchronous JavaScript,scripts executed with this method must explicitly signal they are finished by invoking theprovided callback. This callback is always injected into the executed function as the lastargument.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.