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条)