2016-08-30 8 views
0

sendkeys를 사용하여 파일을 업로드하고 있는데 어떤 이유로 인해 매우 일치하지 않습니다. 파일을 업로드하는 두 가지 시나리오가 있습니다 (기본 창에 파일 첨부 후 두 번째 창에 파일 첨부). 두 번째 창에 파일을 첨부하지 않고 주 창에 파일을 첨부하는 첫 번째 시나리오를 사용하면 완벽하게 작동합니다. 두 번째 창에서도 동일한 작업을 수행했지만 정상적으로 작동하지만 둘 다 실행하면 sendkey가 정확한 문자열을 입력하지 않습니다.Sendkeys가 selenium webdriver에서 일치하지 않습니다.

AttachFileTA.cs :

IWebElement fileAttachTA = driver.FindElement(By.XPath("//object[@class='ruObject']")); 
fileAttachTA.Click(); 

     //Switch into the windows upload dialog 

     Thread.Sleep(1000); 
     SendKeys.SendWait(file); 
     Thread.Sleep(1000); 
     SendKeys.SendWait(@"{Enter}"); 
     Thread.Sleep(1000); 
     SendKeys.Flush(); 

Main.cs :

createDraftTA.FillGeneralInfo("This is a fourth positive test created from Selenium Webdriver"); 
addPrepaid.AddPrePaid("test", "Comment"); 

AddPrepaid.cs : 여기에 코드입니다

commentsBox.SendKeys("COMMENT");   
    CreateTANonProxy_Domestic attachFile = new CreateTANonProxy_Domestic(driver); 
    attachFile.AttachFileTA("\\Users\\My Documents\\file.txt"); 

FillGeneralInfo.cs는

purposeBox.SendKeys(purpose); 
AttachFileTA("\\Users\\My Documents\\file.txt"); 

파일을 업로드하는 가장 좋은 방법은 무엇입니까? 당신이 여기 SendKeys을 오해처럼

감사

모든

답변

0

먼저, 보인다. 코드에서 SendKeys은 C# 클래스이며 셀렌 메서드가 아닙니다.

More about `SendKeys' class

SendKeys (C#을) 클래스는 셀레늄에서 사용할 때 기반의 팝업 창을 전달하기위한 신뢰할 수 없습니다. 대신에 파일 업로드를 위해 다른 대안을 사용해보십시오. AutoIt tool. 위에 AutoIt 작동 방식을 찾아서 Selenium WebDriver에서 파일 업로드를 처리 할 수있는 솔루션을 구현하십시오.

관련 문제