2013-06-20 2 views
-1

5 개의 파일을 업로드하고 싶지만 '파일 입력'은 같은 이름/ID입니다. 어떻게 5 개의 파일을 업로드 할 수 있습니까? 내 HTML 코드는 다음과 같습니다 당신이 하나 개의 파일을 업로드 한 경우셀레늄 webdiver에 여러 파일 업로드

<div> 
    <table id="listtable"> 
    </table> 
    <br/> 
    <input type="hidden" name="delFiles" id="deletefiles"/> 
    <table id="filetable"> 
    <tbody> 
     <tr> 
      <td> 
       <input type="file" size="27px" id="page" name="page"/> 
      </td> 
      <td> 
       <a href="#"> 
        <img name="del" onclick="removeRow(this);" title="delete" alt="delete" src="images/user_delete.png"/> 
       </a> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <input type="file" size="27px" name="page"/> 
      </td> 
      <td> 
       <img name="del" onclick="removeRow(this);" title="delete" alt="delete" src="images/user_delete.png"/> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <input type="file" size="27px" name="page"/> 
      </td> 
      <td> 
       <img name="del" onclick="removeRow(this);" title="delete" alt="delete" src="images/user_delete.png"/> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <input type="file" size="27px" name="page"/> 
      </td> 
      <td> 
       <img name="del" onclick="removeRow(this);" title="delete" alt="delete" src="images/user_delete.png"/> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <input type="file" size="27px" name="page"/> 
      </td> 
      <td> 
       <img name="del" onclick="removeRow(this);" title="delete" alt="delete" src="images/user_delete.png"/> 
      </td> 
     </tr> 
     </tbody> 
    </table> 
    <br/> 
    <br/> 
</div> 
+2

. 답변이 만족스럽지 않으면, 응답을 피드백하십시오. http://meta.stackexchange.com/a/5235 –

+0

@Namitha, 탭 또는 4 칸으로 들여 쓰기하지 않으면 HTML이 표시되지 않습니다. 내가 만든 편집을 롤백하거나 단순히 직접 편집하지 마십시오. – Arran

+0

감사 Arran, 내 문제에 대한 해결책을 줄 수 있습니까? – Namitha

답변

1

당신은 당신이하는 것처럼 그렇게 동일한 기능을 수행 할 것입니다.

driver.findElement(By.id("input1")).sendKeys("path/to/first/file"); 
driver.findElement(By.id("input2")).sendKeys("path/to/second/file"); 
driver.findElement(By.id("input3")).sendKeys("path/to/third/file"); 
driver.findElement(By.id("input4")).sendKeys("path/to/fourth/file"); 
driver.findElement(By.id("input5")).sendKeys("path/to/fifth/file"); 
driver.findElement(By.id("upload")).click(); 

분명히 올바른 ID 등을 입력해야합니다.

+0

하지만 여기에 모든 텍스트 상자 이름 = 페이지. 그래서 어떻게 줄 수 있습니까? – Namitha

+0

여기에 ID가 input1, input2 ...와 다르지만 내 ID는 항상 동일합니다. – Namitha

+0

마크, 이것에 대한 아이디어가 있으십니까? – Namitha

0

성령 ##### 심지어 PHP에서 작동 :

public function waitForAjax() 
{ 
    while(true) 
    { 
     $ajaxIsComplete = array(
      'script' => 'return jQuery.active == 0', 
      'args' => array() 
     ); 
     $ajaxIsComplete = $this->execute($ajaxIsComplete); 
     if ($ajaxIsComplete) { 
      break; 
     } 
    } 
} 

당신을 :) 감사

+0

Ummmm, what ???? – SiKing

0

//input[@type="file"] 첫 번째 입력 태그 및 (//input[@type="file"])[{INDEX}] 를 가리 킵니다 쉽게 처럼 여기서 INDEX는 입력 태그의 수입니다. 참고 : xpath에서의 인덱싱은 1부터 시작합니다.

또는 당신은 그냥 구글 파이썬 구문은 서로 다른 언어를 찾을 수

file_tag_list =driver.find_elements_by_xpath(//input[@type="file"]) 

기능을 사용할 수 있습니다. 이 기능은 webdriver 요소 의 목록을 반환 할 것이다 다음 수

file_tag_list[0].send_keys(filepath) 
file_tag_list[1].send_keys(filepath) 
-1

이는 크롬에서 작동 :

당신은 정말 모든 묻는 질문을 검토하고 답변을 수락해야
driver.findElement(By.id("input1")).sendKeys("path/to/first/file-001 \n path/to/first/file-002 \n path/to/first/file-003");