简体   繁体   English

使用Selenium C#上传文件

[英]Uploading a file with Selenium C#

I'm having a problem managing File upload in Selenium using Chromedriver and C# . 我在使用Chromedriver和C#在Selenium中管理文件上传时遇到问题。 I read a couple of answers to similiar problems regarding the file uploader dialogue window and how this can be solved. 我读了几个关于文件上传器对话窗口的类似问题的答案,以及如何解决这个问题。 The thing is that I don't have the standard input element but instead, I have this: 问题是我没有标准的输入元素 ,而是我有这个:

<div class="scUploadWrapper">
    <div id="Overlay2" class="scUploadOverlay" style="width: 80px; height: 59px;">
        <embed id="yuigen1" type="application/x-shockwave-flash" src="..." style="undefined" name="yuigen1" bgcolor="#ffffff" quality="high" allowscriptaccess="always" wmode="transparent" menu="false" flashvars="allowedDomain=domain.com&elementID=yuigen1&eventHandler=YAHOO.widget.FlashAdapter.eventHandler" tabindex="1" width="100%" height="100%"/>
    </div>
    <a class="scOption" href="#" onclick="javascript:scForm.invoke('media:multiupload(load=1, ownframe=1)');return false">
        <img class="scIcon" src="/temp/IconCache/Applications/32x32/export1.png" alt="" width="32" border="0" height="32"/>
        <div class="scHeader">Upload Files</div>
    </a>
</div>

The thing is that this workaround 问题是这个解决方法

linkUploadFiles.WaitTillVisible(); linkUploadFiles.SendText(@"C:\\Users\\folder\\image.PNG");

is therefore not usable. 因此不可用。 Any ideas what to do with it? 任何想法如何处理它? I'm kinda stuck. 我有点卡住了。 Thanks a lot. 非常感谢。

Selenium can not handle windows based dialogues. Selenium无法处理基于窗口的对话。 Instead use Auto IT scripts. 而是使用Auto IT脚本。
The example script is below. 示例脚本如下。
Modify the script based on the properties of your windows dialogue: 根据Windows对话框的属性修改脚本:

Local $hWnd = WinWait("[CLASS:#32770]", "", 120)
ControlClick($hWnd,"","[CLASS:Edit; INSTANCE:1]")
Send($pathofFile)
Send("{ENTER}")
Exit

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

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