AngularJS form in WebDriver

There is a file upload form with a data type input[type="text" i]. I would like to select and upload a file without Robot classand KeyEvent. Class in the HTML as follows: class="form-control ng-pristine ng-invalid ng-touched".

I am trying to upload a file without opening the file selection window, so use the following code.

driver.findElement(By.cssSelector("myfilepath");

I have an exception and the same thing when I use XPathto identify an object and go through a file.

org.openqa.selenium.ElementNotVisibleException: item not showing

Similar site and shape: https://angular-file-upload.appspot.com/#2

+4
source share
2 answers

input[file] (, CSS) :

driver.findElement(By.cssSelector("input.your-file-input-class")).sendKeys("/my/file/path");

input.your-file-input-class. CSS .

, , - . input[type="text"] , , .

driver.findElement(By.cssSelector("input[type=\"text\"]")).sendKeys("/my/file/path");

, , myfilepath - , . , , :

String myfilepath = "/path/to/file";

driver.findElement(By.cssSelector("input[type=\"text\"]")).sendKeys(myfilepath);

, , , :

WebDriverWait wait = new WebDriverWait(driver, 60); // 1 min timeout
WebElement el = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input[type=\"text\"]")));
el.sendKeys(myfilepath);
+1

javascript

javascript:

var test=document.querySelector('your css selector');

test.setAttribute("value","your path value");

javascript- javascriptExecutor csspathselector,

:

String js = "var test=document.querySelector(arguments[0]);test.setAttribute('value',arguments[1]);";
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript(js, "yourcssSelectorPath","filepath");
+1

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


All Articles