簡體   English   中英

如何在 bamoo headless 中使用 selenium 上傳文件

[英]How to upload a file with selenium in bamoo headless

我正在嘗試通過 selenium 中的瀏覽器測試文件上傳。

設置為:Mac 上的 Eclipse,竹子上的 Selenium Linux, ZD523897880E1EA21381, Chrome

在我的網站上,文件上傳使用按鈕。 此按鈕打開本機瀏覽器文件上傳對話框(無需輸入;該按鈕在 ng-click 上調用 JS)。

<button class="cs-button-link-01" ng-click="uploadFile()" ng-if="context.permissions.edit">
    <i class="cs-icon cs-icon-circle-plus cs-iconsize-200"></i>&nbsp;
    <span cs-translate="'csAssetFileListWidget.AddFileBtn'">File</span>
</button>

So the fileupload works fine for mac and linux on my mac with using a robot class like in File Upload using Selenium WebDriver and Java Robot Class for linux it works well with:

robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.delay( 1000 * 4 );
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);

但是現在我有一個問題,我想在 Bamboo 上運行它(在 Linux 上,無頭)。 (AutoIt 無法工作,因為它的 4 個窗口)

您對如何解決這個問題有任何想法嗎?

在 body 的下方或末尾應該有一個 input 元素。 他將接受來自本機“選擇文件”window 的 select 文件,每個操作系統都不同。

如果您將文件路徑發送到此輸入將觸發輸入。 例子:

<input type="text" id="drive_hist_state" name="drive_hist_state" style="display:none;">


WebElement input = driver.findElement(By.id("drive_hist_state"));
input.sendKeys("/path/to/file/test.txt");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM