简体   繁体   中英

Selenium is taking too much time to execute a command after handing browser authentication pop up

I am facing a very strange issue with Selenium WebDriver. After login into the website, our application shows a basic authentication pop up which I have handled through AutoIT. Problem is after the page load, Selenium takes around 80-100 secs to execute the next command. Next Command could be anything, I am simply trying to get the title of the browser after the page load. After executing the next command in 80-100 secs, Selenium execute the rest of the command in normal speed.

Any idea what could be the issue ? I have added my code below.

            driver.findElement(By.id("username").sendKeys("username");
            driver.findElement(By.id("password").sendKeys("passowrd");
            driver.findElement(By.id("submit").click();


            File file = new File("lib", "jacob-1.17-x64.dll"); 
            System.setProperty(LibraryLoader.JACOB_DLL_PATH,
                    file.getAbsolutePath());
            AutoItX autoIt = new AutoItX();
            Thread.sleep(2000);

            String title = "Authentication Required";


            autoIt.winActivate(title, "");
            autoIt.winWaitActive(title);
            if (autoIt.winExists(title)) {
                autoIt.send("username{TAB}", false);
                autoIt.send("password{Enter}", false);
            }

        } catch (InterruptedException ex) {
            //
        }*/

        System.out.println(driver.getTitle());       


        System.out.println(driver.findElement(By.cssSelector(".sdfsdf")).getText());
        System.out.println(driver.findElement(By.id("key")).getAttribute("placeholder"));

In the above code, Selenium takes around 60-80 secs to execute the get Title command but after that it works pretty normal. Even if I change the order of the command in the code, result remain the same.

@Naseem: How you are saying page is already loaded.? From the code you provided, there is no condition that says to wait until page loads

Anyways, if you are not waiting until document.readystate to complete, I suggest please use the below code and give a try

void waitForLoad(WebDriver driver) {
    ExpectedCondition<Boolean> pageLoadCondition = new
        ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver driver) {
                return ((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete");
            }
        };
    WebDriverWait wait = new WebDriverWait(driver, 30);
    wait.until(pageLoadCondition);
}

Also, Please avoid using Thread.sleep()

If the above code doesn't help then AutoIT code must be the culprit, btw, while using autoIT, what is the "Local Const $timeout" you are using.?

From the below blog, one of such AutoIT code provided.

http://seleniummonk.blogspot.in/p/handle-upload-dialog.html

Try the code from it. Put your observations here, will see if it doesn't fit your needs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM