在Selenium C#隐藏对象中上传图像 [英] Upload image in selenium C# hidden object

查看:81
本文介绍了在Selenium C#隐藏对象中上传图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法上传图片:
代码是:

I am not able to upload image:
The code is:

<div class="divFile">
<div id="FileUploaddiv" style="height: 70px; cursor: pointer;">
<div style="position: relative; margin: 0px; padding: 0px; width: inherit; height: inherit;" class="mf_upload_m">

<div style="position: absolute; text-align: center; z-index: 1; width: 100%; height: 100%; top: 0px; left: 0px; font-size: 13px;" class="mf_upload_ins">
<div class="FileHeading">Select File</div><i class="icon-file-alt icon-2" style="margin-top: 3px;"></i></div></div></div>

<div id="uploaded" style=""></div>
<span style="display: none;" class="reqFile error span2">Please Select File</span>

<input id="hdnParentID" name="hdnParentID" type="hidden">
<input id="hdnDocID" name="hdnDocID" value="0" type="hidden">
<input id="hdnDocFolderID" name="hdnDocFolderID" value="40520" type="hidden">
<input id="hddnIsEdit" name="hddnIsEdit" value="1" type="hidden">
</div>
<div class="divFileName hide"></div>

上传代码:

driver.FindElement(By.XPath("//input[@id='mf_file_FileUploaddiv']")).SendKeys("C:\\Users\\Y.P.Singh\\Desktop\\ETS.txt");

代码已执行,但文件未上传.此外,没有错误.

The code executes but the file is not getting uploaded.Also, No Error is coming.

推荐答案

感谢您的帮助,否则我将无法解决这个问题.我已经用您的技术解决了这个问题,并将其与我在网上研究过的东西混合在一起.

Thank you for your Help without which I will not be able able to solve this issue. I have solved this using your technique and mixed it with something that I researched on the net.

我已经导入了System.Windows.Forms;然后使用此代码

I have imported System.Windows.Forms; and then used this Code to

IWebElement checkbx = driver.FindElement(By.CssSelector("input#mf_file_FileUploaddiv.file"));
Actions actions = new Actions(driver);
actions = actions.MoveToElement(checkbx);
actions = actions.Click();
actions.Build().Perform();
System.Windows.Forms.SendKeys.SendWait("C:\\Users\\Y.P.Singh\\Desktop\\ETS.txt");
System.Windows.Forms.SendKeys.SendWait("{ENTER}");
System.Threading.Thread.Sleep(4000);
driver.SwitchTo().DefaultContent();
System.Threading.Thread.Sleep(10000);
driver.FindElement(By.XPath("//a[@value='SAVE']")).Click();
System.Threading.Thread.Sleep(10000);

这篇关于在Selenium C#隐藏对象中上传图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆