Last active
August 29, 2015 14:22
-
-
Save dck-jp/6bb1686153e2c916fef4 to your computer and use it in GitHub Desktop.
SHDocVwSample08
This file contains hidden or 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 SelectDropDownList() | |
{ | |
var IE = new SHDocVw.InternetExplorer(); | |
IE.Visible = true; | |
object URL = "http://law.e-gov.go.jp/"; | |
IE.Navigate2(ref URL); | |
IE.Wait(); | |
var doc = IE.Document as mshtml.IHTMLDocument3; | |
{//1つ目の方法 | |
var dropdown = doc.getElementsByName("Y_TYPE").item(index: 0) as mshtml.HTMLSelectElement; | |
dropdown.selectedIndex = 1; //Indexで指定する場合 | |
} | |
{//2つ目の方法 | |
var dropdown = doc.getElementsByName("Y_HOREI").item(index: 0) as mshtml.HTMLSelectElement; | |
dropdown.setAttribute("value", "5"); //optionのvalue で選択する場合 (* valueはソースコードを確認する必要あり) | |
} | |
{//3つ目の方法 | |
var dropdown = doc.getElementsByName("Y_TANI").item(index: 0) as mshtml.HTMLSelectElement; | |
foreach (mshtml.HTMLOptionElement option in dropdown.options) | |
{ | |
if (option.innerText.Contains("本則中の条単位"))//テキストベースで選択する場合 | |
{ | |
option.setAttribute("selected", "selected"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment