2010-06-04 1 views
3

C# WATIN을 사용하면 페이지에서 INPUT 태그 html 요소의 두 번째 발생 값을 얻는 방법은 무엇입니까?C# WATIN을 사용하여 INPUT 태그 HTML 요소의 값을 얻는 방법은 무엇입니까?

나는 여러 가지를 시도했지만 성공하지 못했습니다. 디버거는 반환 된 4 개 요소 중에서 [1] 요소를 가져올 명확한 방법을 제공하지 않습니다.

Console.WriteLine(ie.Element(Find.ByClass("myclass")).GetAttributeValue("value") ) ; 
// works but prints the value of the 1st of 4 input elements on the page 

Console.WriteLine(ie.ElementsWithTag("input", "text").Length.ToString() ); 
// returns the number 4 

Console.WriteLine(ie.Element(Find.ByName("login")).GetAttributeValue("value") ); 
// works but its not safe since its possible there might be two elements with the name login 

는 기본적으로, 나는 그것의 배열 인덱스에 의해 입력 요소를 선택할 수 있어야합니다.

답변

3

을 시도해보십시오

 ElementCollection elementCol = ie.Elements; 
     elementCol = elementCol.Filter(Find.ByClass("myclass")); 
     string value = elemntCol[1].GetAttributeValue("value"); 
+0

좋은 아이디어! 감사. ;-) – djangofan

0

이 도울 수

ie.Element(Find.ByIndex(1)) 
0

아무도 더 이상 루프를 사용하지 않습니다? , 내가 실수로 index constraint class에서 더 나은 답변을 가로 질러가있을 수 있다고 생각

TextFieldCollection textFields = browser.TextFields; 
foreach (var field in textFields) 
{ 
    if (field.Id == "humbuggery")... 
} 
+0

... more loop-like, 나는 의미했다 :-) –

0

: 나는 루프 깔끔한 생각 (그리고 Watin 전시는이 동작을/내 점심을 ;-) 훔친 이유의 이해에 훨씬 더 쉽게 그것은 :

ie.Link(new IndexConstraint(1) && Find.ByName("linkname")) 

나는 그것을 연구 할 필요가있다. 나중에이 질문을 다시 살펴 보겠습니다.

+0

@sth - 편집 해 주셔서 감사합니다. 그게 너 좋았어. – djangofan

관련 문제