R
R
RomulFobos2019-04-12 10:07:41
JavaScript
RomulFobos, 2019-04-12 10:07:41

Is it possible to run a js script through a request?

Hello.
I am writing a function to reboot the usb modem through the webmord.
Now I do it with the help of selenium. I open the modem page in headless mode via fierfox, click on the "Restart" button, then on the "OK" confirmation. But the page doesn't always reload. Sometimes the web driver does not see the button and gives an error (although there is an hour-long wait for the button).
I looked at the button code, when you click on it, the reboot.js script is executed.
Can I run it by sending a request?
Just in case, I give an example of code that now presses the "Reload" button.

driver.get("http://192.168.8.1/html/reboot.html");

       WebElement element = (new WebDriverWait(driver, 3600)).until(ExpectedConditions.presenceOfElementLocated(By.id("span_reboot_apply_button")));
       ((JavascriptExecutor) driver).executeScript("arguments[0].click()", element);

        try {
            Thread.sleep(1000 * 5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

       WebElement element_2 = (new WebDriverWait(driver, 3600)).until(ExpectedConditions.presenceOfElementLocated(By.id("pop_confirm")));
        ((JavascriptExecutor) driver).executeScript("arguments[0].click()", element_2);

        System.out.println("Перезагружаем модем...");

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question