Reputation: 353
I'm not able to upload a file and I guess the problem is because input object is hidden!
I have a lot of uploads in my tests but they all use "" and everything works perfectly
This is the first time I have to use something like the code below
Another question is why it works if I start my test from selenium IDE but not when I start it from my framework ( testNG+webdriver)
Code line is:
driver.findElement(By.xpath("//input[@type='file']")).sendKeys("C:\test.txt");
Object structure is:
<button class="btn btn-lg btn-success" flow-btn="">
<span class="glyphicon glyphicon-upload"/>
<span>Upload files</span>
<input type="file" style="visibility: hidden; position: absolute;" multiple="multiple"/>
</button>
Upvotes: 1
Views: 2595
Reputation: 353
Great,
I solved my problem in this way and , it works perfectly! But, I'm wondering if this is the only way. I mean, make the object visible !
String js = "arguments[0].style.visibility = 'visible';";
jse.executeScript(js, element);
element.sendKeys("C:\\test.txt");
String jsa = "arguments[0].style.visibility = 'hidden';";
jse.executeScript(jsa, element);
Upvotes: 1