简体   繁体   中英

File upload SendKyes not working Selenium

Trying to upload file using chromedriver I findelement Browse button and Click() to uploadfile new window opens for entering the path I use SendKyes doesn't type the filepath to

WebElement fileInput = driver.findElement(By.name("btnChooseFiles")); fileInput.sendKeys("C:/path/to/file.jpg");

here is the HTML code

<div style="height: inherit; vertical-align: middle; display: table-cell;">
                            <input name="fileInput" type="file" id="fileInput" onpropertychange="add()" style="position: absolute; visibility: hidden;" multiple="true">
                            <input type="submit" name="btnChooseFiles" value="Browse..." onclick="fileInput.click();return false;" id="btnChooseFiles" class="bluebutton bluebutton32 browsebutton">
                        </div>

To send keys use the following code instead:

string keysToPress = "asdf";
var webDriver = new WebDriver();
var actions = new Actions(webDriver);
actions.SendKeys(keysToPress).Perform();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM