我正在尝试使用c#中的selenium web驱动程序上传文件。
我正在尝试这个: WebDriver.FindElement(By.Name("upload")).SendKeys("C:\Users\test\Desktop\test.cs");
但这是行不通的。
这在selenium IDE中可以正常工作,但在selenium webdriver中不能正常工作。
以下是该页面的HTML代码:
在这里我尝试使用以下元素:<input class="js-attach-file" type="file" tabindex="-1" name="upload">
<!DOCTYPE html>
<html lang="en">
<head>
<body class="page-index firefox firefox-9 windows extra-large-window full-content window-up">
<div id="nocss">
<div id="surface" class="clearfix" style="height: 725px;">
<div class="window-overlay">
<div class="window" style="left: 375px; top: 50px; display: block;">
<div class="window-wrapper clearfix">
<div>
<div class="window-header-utils">
<div class="window-header clearfix">
<div class="window-main-col">
<div class="window-sidebar">
<div class="window-module card-label-list clearfix hide">
<div class="window-module clearfix">
<div class="window-module clearfix attachments">
<h3>Attachments</h3>
<ul class="attachment-list hide"></ul>
<p class="no-attachments empty">No attachments.</p>
<div class="uploader touch-hide">
<form class="realfile" enctype="multipart/form-data" method="post" action="/api/card/4f701c9daf1765861a15545c">
<input type="hidden" value="" name="token">
<input type="hidden" value="attachFile" name="method">
<input type="hidden" value="http" name="format">
<input class="js-attach-file" type="file" tabindex="-1" name="upload">
</form>
<a class="button-link highlight-icon fakefile js-fakefile">
</div>
<p class="error js-file-too-large" style="display:none; -moz-border-radius: 3px; -webkit-border-radius: 3px; font-weight: bold; margin: 8px 0 0; padding: 6px; background: #e3e3e3; ">File too large. 10mb limit.</p>
</div>
<div class="window-module other-actions clearfix">
<div class="window-module quiet-actions clearfix">
</div>
</div>
</div>
</div>
</div>
<div class="pop-over clearfix fancy-scrollbar" style="display: none;">
<script>
<script src="https://d2k1ftgv7pobq7.cloudfront.net/js/78dcaf5810779a263fe6939fc4895487/all.js">
</body>
</html>发布于 2016-01-09 14:01:46
你可以在下面的链接中找到解决方案。你可以使用javascript来解决这个问题。
String script = "document.getElementById('fileName').value='" +"C:\\\\temp\\\\file.txt" + "';";
((IJavascriptExecutor)driver).executeScript(script);发布于 2015-06-07 18:43:51
selenium不能识别或识别属性为file类型的元素。
Like example
<input type="file" id="id1" name="abc"></input>因此,为了处理这种情况,我们必须使用第三方工具,如点位置来计算浏览按钮的x和y坐标。
然后,我们可以使用c#中的低级鼠标单击句柄,也可以使用Autoit V3工具来处理窗口弹出。
您可以在我的博客上找到更多详细信息和完整的解释和实际示例:http://avinashpandeblogsonseleniumautomation.blogspot.in/2015/06/upload-file-using-selenium-web-driver.html
发布于 2012-03-26 22:15:35
如果您使用的是Firefox浏览器而不是Send keys,请使用type。
如果浏览器是IE,则必须使用Autoit或Selenium 2包含方法attach_file或使用this等工具
sel.attach_file("css=inputtype=file",“http://url.com/file.txt"”)
https://stackoverflow.com/questions/9868267
复制相似问题