![](/img/trans.png)
[英]WebDriver file upload through input freezes after sendKeys triggers the upload
[英]Upload file with Webdriver: nothing happens after sendKeys()
我正在嘗試通過Selenium Webdriver自動上傳文件。
我已經在stackoverflow上閱讀了很多與此主題有關的問題,並使用了此處提供的所有技巧,並且我的代碼實際上正在測試頁面上運行: https : //demo.vaadin.com/sampler/#ui/data-input/其它/上傳
但是我無法在我的真實項目中使用它。 首先-我的輸入字段是不可見的,因此我使用以下命令使其可見:
js.executeScript("arguments[0].setAttribute('style', arguments[1])",element, "opacity:100; width:50px");
我確認該字段確實可見。 比我通過sendKeys()方法發送文件的絕對路徑:
Path path = Paths.get(value);
Path absolutePath = path.toAbsolutePath();
sendKeys(absolutePath.toString());
但是當我嘗試檢查該字段的值時:
String v=elem.getAttribute("value");
它總是空的。
我嘗試將錯誤的路徑發送到文件,並且此代碼給了我一個錯誤-不是絕對路徑,因此它的確在嘗試向輸入字段發送內容。
我想這與受測網頁的代碼有關,但是我沒有足夠的知識來分配問題。
輸入元素的HTML代碼如下:
<input type="file" data-bind="attr: {id: uid, name: inputName, multiple: isMultipleFiles}, disable: disabled, afterRender: onElementRender">
以下代碼在C#中為我工作
SendKeys.SendWait(@"D:\filename");
SendKeys.SendWait(@"{Enter}");
添加"using System.Windows.Forms;"
在名稱空間中
在參考中添加"System.Windows.Form"
您可能會發現這是因為文件路徑無效。 確保:
當我在路徑中引入..時,我發現此功能對我無聲地停止工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.