我是网络浏览器自动化的新手,我选择谷歌页面作为学习示例。
我尝试模拟文件上传到 Google Drive,但遇到了几个问题。
http://s4.postimage.org/jbx6c3q3h/Untitled_1.jpg
private void webBrowser_DocumentCompleted ( object sender, WebBrowserDocumentCompletedEventArgs e ) {
HtmlElement element = webBrowser.Document.GetElementById( "contentcreationpane" );
if ( element != null )
UploadFile();
}
private void UploadFile () {
HtmlElementCollection elements = webBrowser.Document.GetElementsByTagName( "div" );
foreach ( HtmlElement element in elements ) {
if ( element.GetAttribute( "data-tooltip" ) == "Upload" ) {
element.InvokeMember( "click" );
break;
}
}
HtmlElement uploadButton = webBrowser.Document.GetElementById( ":1" );
if ( uploadButton != null ) {
uploadButton.InvokeMember( "click" );
} else {
Exception goes here! Is it necessary to do a wait after previous element "Upload" is clicked?
}
}