Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
859 views
by Contributing Tester (20 points)

Hi. I need help. I have element on:

<div class="upload-photo-button">
<input id="upload-photo-button-file" class="cropit-image-input center-block" type="file" accept="image/*">
<label for="upload-photo-button-file"> Выберите файл </label>
</div>
 
in css:
.profile-edit-photo-container .upload-photo-button input[type="file"] {
    display: none;

so i cant upload file because input not visable

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)
selected by
 
Best answer

The quick solution will be to display existing file upload button and set the file to be uploaded.

Eg.

JavascriptExecutor executor = (JavascriptExecutor)driver;
WebElement element = driver.findElement(By.xpath("//input[@type=\"file\"]"));
executor.executeScript("arguments[0].style.display='block';", element);
 
Now, wait for the element to be clickable.
 
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@type=\"file\"]")));
 
 
Now, you can do sendKeys
 
elemenet.sendKeys("/path/to/the/file");
 
Hope that helps!


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...