【问题标题】:File upload SendKyes not working Selenium文件上传 SendKeys 不起作用 Selenium
【发布时间】:2020-10-12 16:45:41
【问题描述】:

尝试使用 chromedriver 上传文件 我 findelement 浏览按钮和 Click() 上传文件 输入路径的新窗口打开我使用 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>

【问题讨论】:

    标签: c# selenium-webdriver


    【解决方案1】:

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

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

    【讨论】:

    • 我假设 KeysToPress 是要上传的文件的路径,对吗?它对我不起作用我得到与 SendKyes 相同的结果。文件路径仍然显示为空
    • 如果您正在谈论的窗口不在浏览器中,那么我认为通过 webdriver 发送密钥不会为您提供所需的功能
    猜你喜欢
    • 1970-01-01
    • 2018-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-21
    • 2013-10-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多