Created
June 6, 2015 11:17
-
-
Save dck-jp/de7985ea015318f11e2b to your computer and use it in GitHub Desktop.
SHDocVwSample07
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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