最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - org.openqa.selenium.TimeoutException: Expected condition failed: waiting for wattzhub.account.UpdatePage$$Lambda -

programmeradmin0浏览0评论

I have a problem with selenium test using java, I want to upload a profile photo but I found errors. Everything works well at first, the photo is downloaded but it does not appear on the screen and the validation button is not clickable knowing that all the paths are 100% correct. I tried several solutions like forcing the click, checking that the button is no longer deactivated,I increased the implicit time but still it doesn't work. This is the response I receive when I run my code: File sent : C:\Users\KATANA\Desktop Image loaded correctly: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQYV2NgAAIAAAUAAarVyFEAAAAASUVORK5CYII=

.openqa.selenium.TimeoutException: Expected condition failed: waiting for wattzhub.account.UpdatePage$$Lambda/0x000001b40122a6f8@5a62b2a4 (tried for 10 second(s) with 500 milliseconds interval)

I hope you can help me resolve this problem and thank you very much in advance.

    public void changeProfilePicture(String imagePath) {
        WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

        By modifyButton = By.xpath("//button[@class='p-element p-button-outlined p-button-secondary ml-auto mr-auto mt-3 mb-3 p-button p-component']");
        WebElement modifyButtonElement = wait.until(ExpectedConditions.elementToBeClickable(modifyButton));
        modifyButtonElement.click();

        By pictureDownload = By.xpath("//div[@class='modal-content']//span[@class='input-browse']");
        WebElement pictureDownloadElement = wait.until(ExpectedConditions.visibilityOfElementLocated(pictureDownload));
        pictureDownloadElement.click();

        By modalContent = By.xpath("//div[@class='modal-content']");
        WebElement modalElement = wait.until(ExpectedConditions.visibilityOfElementLocated(modalContent));
        delay(1000);

        By fileInput = By.id("file-upload");
        WebElement fileInputElement = wait.until(ExpectedConditions.presenceOfElementLocated(fileInput));
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("arguments[0].style.display='block'; arguments[0].style.opacity='1';", fileInputElement);

        fileInputElement.sendKeys(imagePath);
        System.out.println("File sent : " + imagePath);

        By imageElement = By.xpath("//img[contains(@class, 'source-image')]");
        wait.until(ExpectedConditions.presenceOfElementLocated(imageElement));
        WebElement image = driver.findElement(imageElement);


        js.executeScript("arguments[0].style.visibility='visible';", image);


        wait.until(driver -> {
            String visibility = image.getCssValue("visibility");
            return visibility.equals("visible");
        });

        // Validez l'attribut src
        String srcValue = image.getAttribute("src");
        if (srcValue.startsWith("data:image/png;base64,")) {
            System.out.println("Image loaded correctly: " + srcValue);
        } else {
            System.out.println("Image not loaded or invalid src.");
        }
}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论