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

I have a problem with selenium test using java, I want to upload a profile photo but I found errors. Ev

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.");
        }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742409727a4438569.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信