繁体   English   中英

文件上传 SendKyes 不工作 Selenium

[英]File upload SendKyes not working Selenium

尝试使用 chromedriver 上传文件我 findelement Browse 按钮和 Click() to uploadfile new window 打开以输入我使用的路径 SendKyes 没有输入文件路径

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

这是 HTML 代码

<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>

要发送密钥,请改用以下代码:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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