Skip to content

Instantly share code, notes, and snippets.

@dck-jp
Created June 6, 2015 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dck-jp/de7985ea015318f11e2b to your computer and use it in GitHub Desktop.
Save dck-jp/de7985ea015318f11e2b to your computer and use it in GitHub Desktop.
SHDocVwSample07
public void OpenLink()
{
var IE = new SHDocVw.InternetExplorer();
IE.Visible = true;
object URL = "http://www.google.com/";
IE.Navigate2(ref URL);
IE.Wait();
var doc = IE.Document as mshtml.IHTMLDocument3;
doc.getElementById("lst-ib").innerText = "ぐるぐる";
IE.Wait();
doc.getElementsByName("btnK").item(index: 0).click();
IE.Wait(1000);
//googleの検索結果ページは、一旦空のページを表示後、動的に検索結果が追加される仕様のため、
//検索結果の追加が終わるまでの間を1秒として、待機するように
var anchor = doc.getElementsByTagName("A").Cast<mshtml.IHTMLElement>()
.Where(x => x.innerText != null // innerTextがnullの場合があるので注意
&& x.innerText.Contains("Wikipedia"))
.First();
anchor.click();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment