我正嘗試使用Selenium(C#)上傳附件。如何在Selenium中使用Windows上傳對話框處理文件上傳
在檢查網站的DOM時,我注意到附加文件的鏈接是使用object tags
。 下面是HTML摘錄:
<object id="ctl00_mainContent_rauFilessilverlight03" class="ruObject" height="22px" type="application/x-silverlight-2" data="data:application/x-silverlight-2," style="width: 100%;">
<param value="/App/somelongjunkyparameters" name="source"/>
<param value="true" name="windowless"/> <param value="transparent" name="background"/>
<param value="some number" name="minRuntimeVersion"/>
<param value="PostData=anotherlongjunkyparameters,SilverlightRowId=ctl00_mainContent_rauFilessilverlight03,AsyncUploadId=ctl00_mainContent_rauFiles,MultipleSelection=Disabled,AllowedFileExtensions=,ServiceHandlerUrl=/App/Telerik.Web.UI.WebResource type=rau,MaxFileSize=0" name="InitParams"/>
<param value="true" name="autoUpgrade"/>
</object>
到目前爲止,我已經試過這樣:
IWebElement fileAttachTA = driver.FindElement(By.XPath("//object[@class='ruObject']"));
fileAttachTA.Click();
String filePath = "C:/User/My Documents/file.txt";
硒能找到對象,但是,我要切換到Windows上傳對話框?希望聽到任何有此經驗的人。
謝謝!
你的代碼有什麼問題?有什麼異常或其他什麼? –
它只是不會切換到Windows上傳對話框 – Marj