2010-12-29 7 views
0

저는 포럼을위한 로그인 시스템을 개발 중이고 C# .net 형식으로 작동하도록하고 있습니다. 프로그래밍 방식으로 webBrower 컨트롤을 사용하여 포럼의 로그인 버튼을 클릭해야합니다. 지금까지 나는 이것을 가지고있다.webBrower Button 요소 ID가없는 클릭?

webPage page = new webPage(); 
page.URL = txtURL.Text; 
page.Load(); //Load the text from the specified URL 
WebBrowser browser = new WebBrowser(); 
browser.Document.GetElementById("navbar_username").SetAttribute("value", textBox1.Text); 
browser.Document.GetElementById("navbar_password").SetAttribute("value", textBox2.Text); 

HtmlElement el = browser.Document.All["btnI"]; 
if (el != null) 
{ 
    el.InvokeMember("click"); 
} 
else 
{ 
    MessageBox.Show("There is an issue with the program"); 
} 

문제는 페이지의 로그인 버튼이 ID 또는 내가 그것을 클릭 할 수 있도록 할 수있는 모든 실제 정보가없는 것입니다. 누구든지 어떤 제안이 있습니까? 다음은 로그인 버튼의 코드입니다.

<input type="image" src="images/loginbutton.png" class="loginbutton" tabindex="104" value="Log in" title="Enter your username and password in the boxes provided to login, or click the 'register' button to create a profile for yourself." accesskey="s"> 

답변

1

입력 버튼에는 페이지 내에서 고유 한 accesskey 속성이 있습니다.

모든 입력 버튼을 반복하고 s으로 설정된 accesskey 속성이있는 것을 찾으십시오. 이 버튼이 제출 버튼이 될 것입니다.

는 jQuery를 사용하면이 요소를 선택하기 위해 다음을 사용 :

$('input[accesskey="s"]') 
0

당신은 모든는 HTMLElement를 통해 당신은 루프를 할 수있는 것보다 webBrowser1.Document.GetElementsByTagName("input")
를 사용하여 알맞은 값이 버튼이보다 element.innerText == "Log in"
를 찾을 수 있습니다. ..

2

양식을 제출할 수 있습니까? 해당 페이지에 더 많은 버튼이 있습니까?

+0

왜 downvote입니까? 키스. – ncases

+0

예, 3 명이 있습니다. – Jeremy

관련 문제