Selenium Javascript executor don't finish - IE11, Edge IE mode

94 Views Asked by At

Hello I have problem with javascript excecutor in Selenium Browser: Edge IE mode;IE11.
Script don't finish working. I run button where after click show window Windows10 I use method:

public void clickJS(WebElement webElement, String nameElement) throws InterruptedException
    {
        
    waitUntilElementToBeClickable(webElement);
    System.out.println("    Akcja - kliknięcie JS w obiekt: '"+nameElement+"'");
    JavascriptExecutor executor = (JavascriptExecutor)driver;
    executor.executeScript("arguments[0].click()", webElement);
    } 
        
@FindBy(css = "input[id='form1:Postepowanie_Pisma_DodajCnt:fileUpload_plik']")
WebElement epwdButtonWybierzPlik;

System.out.println("Rozpoczeło się wykonywanie skryptu js");
test.autoAction.clickJS(test.pomEpwd.epwdButtonWybierzPlik(), "inputDodajPismo");
System.out.println("Zakończyło się wykonywanie skryptu js

Any Ideas ?

1

There are 1 best solutions below

0
Yu Zhou On

What do you mean "Script don't finish working"? Do you mean executeScript doesn't work or the methods after it doesn't work? Is there any error message?

I made tests with code below and it works well, you can refer to my code sample. You can try to add wait after executeScript.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerOptions;
import org.openqa.selenium.JavascriptExecutor;

public class edgeiemode {
    public static void main(String[] args) throws Exception {
        InternetExplorerOptions ieOptions = new InternetExplorerOptions();
        ieOptions.attachToEdgeChrome();
        ieOptions.withEdgeExecutablePath("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe");

        WebDriver driver = new InternetExplorerDriver(ieOptions);
        try {
            JavascriptExecutor js = (JavascriptExecutor) driver;

            driver.get("https://demo.guru99.com/V4/");
            WebElement button = driver.findElement(By.name("btnLogin"));

            driver.findElement(By.name("uid")).sendKeys("your_username");
            driver.findElement(By.name("password")).sendKeys("your_password");

            js.executeScript("arguments[0].click();", button);
            js.executeScript("alert('Welcome to Guru99');");
            Thread.sleep(5000);
        } finally {
            driver.quit();
        }
    }
}