How to automate boot download boot file using webdriver

I want to automate the file upload process, which uses the file upload control built into bootstrap. I am doing the same with webdriver. Below is my code, but unfortunately it does not work:

element=driver.findElement(By.xpath("//[@id='upload']/fieldset/div[2]/input[1]")); element.sendKeys(pathToFile); 

It gives an element not visible error.

Here is an example of a bootstrap boot control that I am trying to automate via JavaScript: at this URL http://markusslima.imtqy.com/bootstrap-filestyle/ See below style

 $(":file").filestyle({icon: false}); 
+5
source share
1 answer

Ok I think I solved it.

  WebElement fileInput = driver.findElement(By.id("document")); JavascriptExecutor js = (JavascriptExecutor) driver; WebElement element = driver.findElement(By.id("document")); js.executeScript("arguments[0].setAttribute('style', 'left:30px')", element); fileInput.sendKeys(fileName); 

bootstrap-filestyle.js hides the input element, so you need to move it to the visible area and then set it in the standard way.

so many problems for such an easy solution.

Here is my original html code:

 <span id="documentUpload"> <input type="file" id="document" name="document" class="notMandatory" onkeypress="return noenter(event)" tabindex="-1" style="position: absolute; left: -9999px;"> <div class="bootstrap-filestyle" style="display: inline;" tabindex="0"> <input type="text" class="input-xlarge" disabled="" autocomplete="off"> <label for="document" class="btn"><i class="icon-folder-open"></i> <span>Upload</span></label> </div> </span> 
+2
source

Source: https://habr.com/ru/post/1216152/


All Articles