2012-03-12 3 views
1

제출이 실패 할 때 웹 양식이 선택된 요소를 유지하는지 테스트하려면 여러 선택 요소의 선택을 반전하고 (선택 항목이 무엇인지 미리 모르는 상태에서) 해당 선택 항목을 저장하고 clickAndWaitsubmit 버튼과 assert 버튼을 저장하고 싶습니다. 그 선택은 변하지 않는다. selectxpath=//option[(not(@selected))]과 같은 값을 지원하지 않는 것 같습니다. 이렇게 할 수있는 쉬운 방법이 있습니까?Selenium IDE에서 선택을 반전하는 방법은 무엇입니까?

addSelection | element | * 
removeSelection | element | @selected 
storeSelected | element | selectedElements 

불행히도 *select* 명령 모두는 하나의 요소로 작동하는 것, 그리고 XPath를 지원하지 않는, 그래서 그 쉬운 일이 아니다 : 내 첫번째 생각은 이런 식으로 뭔가를하는 것입니다.

답변

1

난 당신이 정확히 의미한다면 모르겠지만 : 사이트에 배치 웹 양식에

: 모든 addSelections한다고 가정

addSelection | xpath=(//select[@name='jezyk'])[4] | label=Polski 
addSelection | xpath=(//select[@name='jezyk'])[4] | label=Niemiecki 
storeSelectedLabels | xpath=(//select[@name='jezyk'])[4] | selected 
//clicking SUBMIT button 
verifySelectedLabels | xpath=(//select[@name='jezyk'])[4] | ${selected} 

:이 코드는 나를 위해 일한 http://www.poradnik-webmastera.com/kursy/html/formularze.php

는 무작위이며, "storeSelectedLabels"는 모든 선택 사항을 저장 한 다음 제출 버튼을 클릭하는 상상의 동작을 수행 한 다음 선택 사항의 확인 (또는 주장)입니다.

+0

이해가 안 - 어떻게 * 반전 * 현재의 선택에 가정 두 가지 선택을 추가? – l0b0

0

아니요, 아닙니다. 나는 너의 요점을 모르겠다. 미안. 나는 다중 선택 요소의 선택을 반전하기를 원한다면

어쨌든, 난 (페이지에서이 세 요소의 드롭 다운에 관하여 내가 전에 제공)과 같이 그것을 할 수 있습니다 :

storeSelectedIndexes | xpath=(//select[@name='jezyk'])[4] | selected 
removeAllSelections | xpath=(//select[@name='jezyk'])[4] 
store | ${selected} | selected2 
store | javascript{storedVars['selected2'].split(',').length} | selectedNo 
store | 999 | selectedIndexNo0 
store | 999 | selectedIndexNo1 
store | 999 | selectedIndexNo2 
store | -1 | loop1 
while | ${loop1} < (${selectedNo} - 1) 
store | javascript{storedVars.loop1++} 
store | javascript{storedVars['selected2'].split(',')[storedVars['loop1']]} | selectedIndexNo${loop1} 
endWhile | 
store | -1 | loop2 
while | ${loop2} < 2 
store | javascript{storedVars.loop2++} 
gotoIf | ${loop2} == ${selectedIndexNo0} || ${loop2} == ${selectedIndexNo1} || ${loop2} == ${selectedIndexNo2} | dontSelect 
addSelection | xpath=(//select[@name='jezyk'])[4] | index=${loop2} 
label | dontSelect 
endWhile | 

을 그것은 가장 쉬운 방법이 아니다 , 나는 생각하지만, 작동합니다.

세 개의 다중 선택 요소에 적합합니다.

첫 번째 루프 (while - endWhile)는 선택된 인덱스를 추출하고 두 번째 루프는 이전에 선택된 인덱스를 제외한 모든 요소를 ​​선택합니다.


좋아, 나는 몇 가지 변화를 만들어 스크립트의이 버전 (한 첫 번째 레이블 인덱스 = 0이 있기 때문에) 어떤 크기의 요소로 사용하기 괜찮습니다. 첫 번째 명령에서 검사 된 다중 형식에 대해 id 또는 xpath를 입력하고 요소에있는 모든 레이블의 수를 storeXpathCount 또는 단순히 그 수를 입력하여 제공하십시오. 그리고 다중 형식의 크기에 따라 "gotoIf"명령에 더 많거나 적은 조건을 추가하십시오. 스크립트의

2 버전 :

//store | put here id or xpath of your dropdown | elementID 
store | xpath=(//select[@name='jezyk'])[4] | elementID 
storeSelectedIndexes | ${elementID} | selected 
removeAllSelections | ${elementID} 
store | ${selected} | selected2 
store | javascript{storedVars['selected2'].split(',').length} | selectedNo 
//use custom xpath or explicitly type number of labels using simple "store" command instead of "storeXpathCount" 
storeXpathCount | //div[@id='content']/div/div[2]/div[31]/div/select/option | elementSize 
store | -1 | loop0 
while | ${loop0} < ${elementSize} 
store | javascript{storedVars.loop0++} 
store | 999 | selectedIndexNo${loop0} 
endWhile | 
store | -1 | loop1 
while | ${loop1} < (${selectedNo} - 1) 
store | javascript{storedVars.loop1++} 
store | javascript{storedVars['selected2'].split(',')[storedVars['loop1']]} | selectedIndexNo${loop1} 
endWhile | 
store | -1 | loop2 
while | ${loop2} < (${elementSize} - 1) 
store | javascript{storedVars.loop2++} 
//depending on size of your multiform element you have to add more conditions to below "gotoIf" command. At the moment it's good for three elements (labels) 
gotoIf | ${loop2} == ${selectedIndexNo0} || ${loop2} == ${selectedIndexNo1} || ${loop2} == ${selectedIndexNo2} | dontSelect 
addSelection | ${elementID} | index=${loop2} 
label | dontSelect 
endWhile | 
관련 문제