public override void AddSelectListItem(string IEName, IHTMLElement ActiveElement, bool ByValue) { string strElement = DetermineFindMethod(IEName, ActiveElement); if (ByValue) { strElement += "->SelectByValue(\"" + ActiveElementAttribute(ActiveElement, "value") + "\");"; } else { mshtml.IHTMLSelectElement sel = ActiveElement as mshtml.IHTMLSelectElement; for (int i = 0; i < sel.length; i++) { mshtml.IHTMLOptionElement op = sel.item(i, i) as mshtml.IHTMLOptionElement; if (op.selected) { strElement += "->SelectByText(\"" + op.text + "\");"; break; } } } AddScriptLine(strElement); }
public void SetWindowProperties(WatinScript watscript, string BrowserName, IHTMLElement element) { tabControl1.SelectedTab = pageMethods; wscript = watscript; browsername = BrowserName; currentelement = element; this.Text = "Property Explorer - " + element.GetType().ToString(); IHTMLDOMNode node = element as IHTMLDOMNode; gridProperties.Rows.Add("tagName", element.tagName); foreach (IHTMLDOMAttribute attr in node.attributes) { if (attr.specified) { gridProperties.Rows.Add(attr.nodeName, attr.nodeValue); } } gridProperties.Rows.Add("innerHTML", element.innerHTML); gridProperties.Rows.Add("innerText", element.innerText); gridProperties.Rows.Add("outerHTML", element.outerHTML); gridProperties.Rows.Add("outerText", element.outerText); rbSelectByText.Enabled = false; comboSelectByText.Enabled = false; rbSelectByValue.Enabled = false; comboSelectByValue.Enabled = false; rbSetFilename.Enabled = false; txtSetFilename.Enabled = false; btnSetFilename.Enabled = false; rbChecked.Enabled = false; rbUnchecked.Enabled = false; string tagtype = watscript.ActiveElementAttribute(element, "type").ToLower(); if (element.tagName.ToLower() == "input" && tagtype == "file") { rbSetFilename.Enabled = true; txtSetFilename.Enabled = true; btnSetFilename.Enabled = true; } else if (element.tagName.ToLower() == "input" && (tagtype == "radio" || tagtype == "checkbox")) { rbChecked.Enabled = true; rbUnchecked.Enabled = true; } else if (element.tagName.ToLower() == "select") { rbSelectByText.Enabled = true; comboSelectByText.Enabled = true; rbSelectByValue.Enabled = true; comboSelectByValue.Enabled = true; comboSelectByText.Items.Clear(); comboSelectByValue.Items.Clear(); mshtml.IHTMLSelectElement sel = element as mshtml.IHTMLSelectElement; if (sel == null) { return; } for (int i = 0; i < sel.length; i++) { mshtml.IHTMLOptionElement op = sel.item(i, i) as mshtml.IHTMLOptionElement; comboSelectByText.Items.Add(op.text); if (op.value == null) { comboSelectByText.Items.Add(op.text); } else { comboSelectByValue.Items.Add(op.value); } } } }
void AddTestStep(HtmlElement element, String elementXPosition, String elementYPosition) { stepsList.SelectionBullet = true; WebBrowser browser = new WebBrowser(); if (tabControl2.SelectedIndex == 0) { browser = webBrowser1; } else { browser = webBrowser2; } //on, in, to String intent = "on"; //value of input field var inputValue = ""; // value of select list var selectValue = ""; // Check what type of element has been selected var elementType = ""; switch (element.TagName.ToLower()) { case "input": elementType = "input field"; intent = "in"; try { mshtml.IHTMLInputElement input = element.DomElement as mshtml.IHTMLInputElement; inputValue = input.value; } catch { } break; case "select": elementType = "select list"; intent = "on"; try { mshtml.IHTMLSelectElement select = element.DomElement as mshtml.IHTMLSelectElement; mshtml.HTMLOptionElement option = (mshtml.HTMLOptionElement)select.item(select.selectedIndex, null); if (select.selectedIndex != 0) { selectValue = option.text; } } catch { } break; case "a": elementType = "link"; intent = "on"; break; case "button": intent = "on"; elementType = "Button"; break; case "img": intent = "on"; elementType = "Slide"; break; } // Check if the selected element has an associated label we can use var elementLabel = ""; var labels = browser.Document.GetElementsByTagName("label"); foreach (HtmlElement lbl in labels) { //check if element has an ID so we can obtain a label for it if (element.Id != null) { //check if the current label for attribute matches one for our element //@'for=\"name"' String forLabel = lbl.OuterHtml.Replace("\"", ""); if (forLabel.Contains("for=" + element.Id)) { elementLabel = lbl.OuterText; } } } //get image alt text // vScreen products use images for slides!! if (elementType == "Slide") { mshtml.IHTMLImgElement img = element.DomElement as mshtml.IHTMLImgElement; //GenerateAndAddExpectedTextStep(elementType, img.alt, elementYPosition, elementXPosition); //BUG: Currently outputs i.e. **USER** even if we're not recording a valid action if (outputUser == true) { stepsList.SelectionBullet = false; //record which user is recording an action stepsList.AppendText("**" + user.ToUpper() + "**" + Environment.NewLine); //we only want to record the user when recording a new list of steps before an expected result outputUser = false; } stepsList.SelectionBullet = true; stepsList.AppendText(string.Format("Click {0} '{1}' {2}{4}", intent, img.alt, elementType, user.ToUpper(), Environment.NewLine)); } // get text for link if (elementType == "link") { elementLabel = element.InnerText; intent = "on"; } // check if we're dealing with a an input button/submit/reset if (elementType == "input field" && elementLabel == "") { try { mshtml.IHTMLInputButtonElement button = element.DomElement as mshtml.IHTMLInputButtonElement; elementType = "button"; intent = "on"; elementLabel = button.value; if (elementLabel == null) { elementLabel = button.name; } } catch (Exception ex) { intent = "in"; elementType = "input"; } } if (element.TagName == "BUTTON") { mshtml.IHTMLElement button = element.DomElement as mshtml.IHTMLElement; //BUG: Currently outputs i.e. **USER** even if we're not recording a valid action if (outputUser == true) { stepsList.SelectionBullet = false; //record which user is recording an action stepsList.AppendText("**" + user.ToUpper() + "**" + Environment.NewLine); //we only want to record the user when recording a new list of steps before an expected result outputUser = false; } stepsList.SelectionBullet = true; stepsList.AppendText(string.Format("Click {0} '{1}' {2}{4}", intent, button.innerHTML, elementType, user.ToUpper(), Environment.NewLine)); } //check type of input if (element.TagName == "SELECT") { if (!string.IsNullOrWhiteSpace(selectValue)) { //BUG: Currently outputs i.e. **USER** even if we're not recording a valid action if (outputUser == true) { stepsList.SelectionBullet = false; //record which user is recording an action stepsList.AppendText("**" + user.ToUpper() + "**" + Environment.NewLine); //we only want to record the user when recording a new list of steps before an expected result outputUser = false; } stepsList.SelectionBullet = true; stepsList.AppendText(string.Format("Select '{0}'{2}", selectValue, user.ToUpper(), Environment.NewLine)); } else { //BUG: Currently outputs i.e. **USER** even if we're not recording a valid action if (outputUser == true) { stepsList.SelectionBullet = false; //record which user is recording an action stepsList.AppendText("**" + user.ToUpper() + "**" + Environment.NewLine); //we only want to record the user when recording a new list of steps before an expected result outputUser = false; } stepsList.SelectionBullet = true; if (RecordElementPosition == true) { // we found the label associated to the selected input and it doesn't have a value input stepsList.AppendText(string.Format("Click {0} '{1}' {2} toward {4} {5} of page{6}", intent, elementLabel, elementType, user.ToUpper(), elementYPosition, elementXPosition, Environment.NewLine)); } else { // we found the label associated to the selected input and it doesn't have a value input stepsList.AppendText(string.Format("Click {0} '{1}' {2}{4}", intent, elementLabel, elementType, user.ToUpper(), Environment.NewLine)); } } } else { //check if input has a value if (string.IsNullOrWhiteSpace(inputValue)) { if (!string.IsNullOrWhiteSpace(elementLabel) && !string.IsNullOrWhiteSpace(elementType)) { //BUG: Currently outputs i.e. **USER** even if we're not recording a valid action if (outputUser == true) { stepsList.SelectionBullet = false; //record which user is recording an action stepsList.AppendText("**" + user.ToUpper() + "**" + Environment.NewLine); //we only want to record the user when recording a new list of steps before an expected result outputUser = false; } stepsList.SelectionBullet = true; if (RecordElementPosition == true) { // we found the label associated to the selected input and it doesn't have a value input stepsList.AppendText(string.Format("Click {0} '{1}' {2} toward {4} {5} of page{6}", intent, elementLabel, elementType, user.ToUpper(), elementYPosition, elementXPosition, Environment.NewLine)); //stepsList.AppendText(string.Format("**{3}**{6}Click {0} '{1}' {2} toward {4} {5} of page{6}", intent, elementLabel, elementType, user.ToUpper(), elementYPosition, elementXPosition, Environment.NewLine)); } else { // we found the label associated to the selected input and it doesn't have a value input stepsList.AppendText(string.Format("Click {0} '{1}' {2}{4}", intent, elementLabel, elementType, user.ToUpper(), Environment.NewLine)); //stepsList.AppendText(string.Format("**{3}**{4}Click {0} '{1}' {2}{4}", intent, elementLabel, elementType, user.ToUpper(), Environment.NewLine)); } } } else { if (elementType == "button") { //BUG: Currently outputs i.e. **USER** even if we're not recording a valid action if (outputUser == true) { stepsList.SelectionBullet = false; //record which user is recording an action stepsList.AppendText("**" + user.ToUpper() + "**" + Environment.NewLine); //we only want to record the user when recording a new list of steps before an expected result outputUser = false; } stepsList.SelectionBullet = true; if (RecordElementPosition == true) { // we found the label associated to the selected input and it doesn't have a value input stepsList.AppendText(string.Format("Click {0} '{1}' {2} toward {4} {5} of page{6}", intent, elementLabel, elementType, user.ToUpper(), elementYPosition, elementXPosition, Environment.NewLine)); } else { // we found the label associated to the selected input and it doesn't have a value input stepsList.AppendText(string.Format("Click {0} '{1}' {2}{4}", intent, elementLabel, elementType, user.ToUpper(), Environment.NewLine)); } } else { //BUG: Currently outputs i.e. **USER** even if we're not recording a valid action if (outputUser == true) { stepsList.SelectionBullet = false; //record which user is recording an action stepsList.AppendText("**" + user.ToUpper() + "**" + Environment.NewLine); //we only want to record the user when recording a new list of steps before an expected result outputUser = false; } stepsList.SelectionBullet = true; // we found the label associated to the selected input stepsList.AppendText(string.Format("Input '{0}'{2}", inputValue, user.ToUpper(), Environment.NewLine)); } } } stepsList.SelectionBullet = false; ScrollToRecordedStepsEnd(); }
//実行 MAIN public void DoAll() { //SavePdf("aaaa.csv") Pub_Com = new Com("納期指定発注" + DateTime.Now.ToString("yyyyMMddHHmmss")); if (Pub_Com.file_list_Nouki.Count == 0) { ProBar = 100; return; } lv1 = System.Convert.ToDecimal(90 / Pub_Com.file_list_Nouki.Count); lv2 = lv1 / 15; //一回目 bool firsOpenKbn = true; object authHeader = "Authorization: Basic " + Convert.ToBase64String(System.Text.UnicodeEncoding.UTF8.GetBytes(string.Format("{0}:{1}", Pub_Com.user, Pub_Com.password))) + "\\r\\n"; //*** OnSiteパスワード入力画面 Ie.Navigate(Pub_Com.url, null, null, null, authHeader); Ie.Silent = true; Ie.Visible = IeVisible; ProBar = 5; //***ログイン DoStep1_Login(); //CSV ファイルs 取込 ProBar = 10; for (int fileIdx = 0; fileIdx <= Pub_Com.file_list_Nouki.Count - 1; fileIdx++) { string csvFileName = System.Convert.ToString(Pub_Com.file_list_Nouki[fileIdx].ToString().Trim()); string[] csvNameSplitor = csvFileName.Split('-'); string 事業所 = csvNameSplitor[0]; string 得意先 = csvNameSplitor[1]; string 店 = csvNameSplitor[2]; string 現場名 = csvNameSplitor[3]; string 備考 = csvNameSplitor[4]; string 日付連番 = csvNameSplitor[5]; //一回目ではなく 実行 if (firsOpenKbn == false) { Pub_Com.GetElementBy(ref Ie, "fraHead", "input", "value", "絞込検索").click(); Pub_Com.SleepAndWaitComplete(Ie); } firsOpenKbn = false; AddProBar(lv2); //1 Pub_Com.AddMsg("取込:" + Pub_Com.file_list_Nouki[fileIdx].ToString().Trim()); //見積検索 Pub_Com.AddMsg("見積検索"); DoStep1_PoupuSentaku(事業所, 得意先, 店, 現場名, 備考, 日付連番, csvFileName); Pub_Com.SleepAndWaitComplete(Ie); AddProBar(lv2); //2 //納期日設定 if (!DoStep2_Set()) { continue; } Pub_Com.SleepAndWaitComplete(Ie); Pub_Com.SleepAndWaitComplete(Ie); Pub_Com.SleepAndWaitComplete(Ie); //該当データがありません NEXT mshtml.HTMLWindow2 fraTmp = Pub_Com.GetFrameByName(ref Ie, "fraHyou"); if (fraTmp != null) { if (fraTmp.document.body.innerText.IndexOf("該当データがありません") >= 0) { continue; } } //CSVファイル内容取込 string[] csvDataLines = System.IO.File.ReadAllLines(Pub_Com.folder_Nouki + csvFileName); string code = ""; string nouki = ""; AddProBar(lv2); //3 mshtml.HTMLWindow2 fra = Pub_Com.GetFrameWait(ref Ie, "fraMitBody"); mshtml.HTMLDocument Doc = (mshtml.HTMLDocument)fra.document; mshtml.IHTMLElementCollection eles = Doc.getElementsByTagName("input"); //Radio 明細Key mshtml.IHTMLElementCollection cbEles = Doc.getElementsByName("strMeisaiKey"); //指定納期 mshtml.IHTMLElementCollection nouhinDateEles = Doc.getElementsByName("strSiteiNouhinDate"); int csvIdx = 0; int sameCdSuu = 0; int gamenSameCdSuu = 0; //CSV LINES for (int csvLinesIdx = 0; csvLinesIdx <= csvDataLines.Length - 1; csvLinesIdx++) { if (!string.IsNullOrEmpty(csvDataLines[csvLinesIdx].Trim())) { //コード 納期 code = System.Convert.ToString(csvDataLines[csvLinesIdx].Split(',')[1].Trim()); nouki = System.Convert.ToString((System.Convert.ToDateTime(csvDataLines[csvLinesIdx].Split(',')[2].Trim())).ToString("yyyy/MM/dd")); sameCdSuu = 0; gamenSameCdSuu = 0; for (csvIdx = 0; csvIdx <= csvLinesIdx; csvIdx++) { if (csvDataLines[csvIdx].Split(',')[1].Trim() == code) { sameCdSuu++; } } for (int i = 0; i <= cbEles.length - 1; i++) { mshtml.IHTMLElement cb = (mshtml.IHTMLElement)(cbEles.item(i)); mshtml.IHTMLTableRow tr = (mshtml.IHTMLTableRow)cb.parentElement.parentElement; mshtml.HTMLTableCell td = (mshtml.HTMLTableCell)(tr.cells.item(1)); mshtml.IHTMLTable table = (mshtml.IHTMLTable)cb.parentElement.parentElement.parentElement.parentElement; bool isHaveDate = false; if (td.innerText == code) { gamenSameCdSuu++; if (sameCdSuu == gamenSameCdSuu) { mshtml.IHTMLSelectElement sel = (mshtml.IHTMLSelectElement)(nouhinDateEles.item(i)); for (int j = 0; j <= sel.length - 1; j++) { mshtml.IHTMLOptionElement opEle = (mshtml.IHTMLOptionElement)(sel.item(j)); if (opEle.value.IndexOf(nouki) > 0) { opEle.selected = true; isHaveDate = true; break; } } } else { continue; } if (!isHaveDate) { MessageBox.Show("コード:[" + code + "] 納品希望日:[" + nouki + "]がありません"); return; } } } } } AddProBar(lv2); //4 Pub_Com.GetElementBy(ref Ie, "fraMitBody", "select", "name", "strBukkenKbn").setAttribute("value", "01"); Pub_Com.GetElementBy(ref Ie, "fraMitBody", "input", "value", "発 注").click(); Pub_Com.SleepAndWaitComplete(Ie); Pub_Com.SleepAndWaitComplete(Ie); Pub_Com.SleepAndWaitComplete(Ie); AddProBar(lv2); //5 Pub_Com.GetElementBy(ref Ie, "fraMitBody", "input", "value", "発注結果照会へ").click(); Pub_Com.SleepAndWaitComplete(Ie); AddProBar(lv2); //6 //PDF 印刷 if (insatu) { SHDocVw.InternetExplorerMedium childIe = default(SHDocVw.InternetExplorerMedium); int RebackKaisu = -1; Reback: RebackKaisu++; Com.Sleep5(1000); //前回印刷画面 Close ClosePrintPage(); Pub_Com.GetElementBy(ref Ie, "fraMitBody", "input", "value", "結果印刷").click(); int wait_print; wait_print = int.Parse(Com.GetAppSetting("wait_print")); AutoResetEvent myEvent = new AutoResetEvent(false); myEvent.WaitOne(wait_print * 1000); myEvent.Close(); try { //印刷画面取得する childIe = GetPrintPage(); } catch (Exception) { } Com.Sleep5(1000); //IE エラー判定する if (GetErrCon() == false) { Com.Sleep5(1000); if (RebackKaisu <= 1) { goto Reback; } else { if (MessageBox.Show("帳票Download エラーしました、終了ですか?", "Confirm Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { System.Environment.Exit(0); } } } string flName = Pub_Com.pdfPath + csvFileName; try { bool rtv = GetFcwInfo(childIe, flName); ClosePrintPage(); if (rtv == false) { if (RebackKaisu <= 1) { goto Reback; } else { if (MessageBox.Show("帳票Download エラーしました、終了ですか?", "Confirm Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { System.Environment.Exit(0); } } } } catch (Exception) { ClosePrintPage(); if (RebackKaisu <= 1) { goto Reback; } else { if (MessageBox.Show("帳票Download エラーしました、終了ですか?", "Confirm Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { System.Environment.Exit(0); } } } } AddProBar(lv2); //10 Pub_Com.AddMsg("移動CSV:" + csvFileName + "→" + Pub_Com.folder_Nouki_kanryou); Com.MoveFile(Pub_Com.folder_Nouki + csvFileName, Pub_Com.folder_Nouki_kanryou + csvFileName); AddProBar(lv2); //11 Pub_Com.GetElementBy(ref Ie, "fraMitMenu", "a", "innertext", "[見積一覧を再表示]").click(); Pub_Com.SleepAndWaitComplete(Ie); } ProBar = 100; }
void AddExpectedResult(HtmlElement element, String elementXPosition, String elementYPosition) { // whether or not to output the actor in the test steps script outputUser = true; //ensure bullet list for new line is off for expected result stepsList.SelectionBullet = false; //check which browser window is recording the result WebBrowser browser = new WebBrowser(); if (tabControl2.SelectedIndex == 0) { browser = webBrowser1; } else { browser = webBrowser2; } var elementType = ""; switch (element.TagName.ToLower()) { case "a": elementType = "Link"; GenerateAndAddExpectedTextStep(elementType, element.InnerText, elementYPosition, elementXPosition); break; case "h1": elementType = "page heading"; GenerateAndAddExpectedTextStep(elementType, element.InnerText, elementYPosition, elementXPosition); break; case "h2": elementType = "page heading"; GenerateAndAddExpectedTextStep(elementType, element.InnerText, elementYPosition, elementXPosition); break; case "h3": elementType = "page heading"; GenerateAndAddExpectedTextStep(elementType, element.InnerText, elementYPosition, elementXPosition); break; case "h4": elementType = "page heading"; GenerateAndAddExpectedTextStep(elementType, element.InnerText, elementYPosition, elementXPosition); break; case "h5": elementType = "page heading"; GenerateAndAddExpectedTextStep(elementType, element.InnerText, elementYPosition, elementXPosition); break; case "h6": elementType = "page heading"; GenerateAndAddExpectedTextStep(elementType, element.InnerText, elementYPosition, elementXPosition); break; case "p": elementType = "page text"; GenerateAndAddExpectedTextStep(elementType, element.InnerText, elementYPosition, elementXPosition); break; case "span": elementType = "page"; GenerateAndAddExpectedTextStep(elementType, element.InnerText, elementYPosition, elementXPosition); break; case "label": elementType = "Label"; GenerateAndAddExpectedTextStep(elementType, element.InnerText, elementYPosition, elementXPosition); break; case "div": elementType = "page text"; GenerateAndAddExpectedTextStep(elementType, element.InnerText, elementYPosition, elementXPosition); break; case "img": elementType = "Image"; mshtml.IHTMLImgElement img = element.DomElement as mshtml.IHTMLImgElement; GenerateAndAddExpectedTextStep(elementType, img.alt, elementYPosition, elementXPosition); break; case "input": //check if regular input or a button! try { mshtml.IHTMLInputElement input = element.DomElement as mshtml.IHTMLInputElement; if (input.type.ToLower() == "text") { elementType = "Input"; // Check if the selected element has an associated label we can use var inputLabel = ""; var inputLabels = browser.Document.GetElementsByTagName("label"); foreach (HtmlElement lbl in inputLabels) { //check if element has an ID so we can obtain a label for it if (element.Id != null) { //check if the current label for attribute matches one for our element String forLabel = lbl.OuterHtml.Replace("\"", ""); if (forLabel.Contains("for=" + element.Id)) { inputLabel = lbl.OuterText; } } } string inputValue = ""; if (input.value == null) { inputValue = input.name; } else { inputValue = input.value; } if (RecordElementPosition == true) { stepsList.AppendText(string.Format("{5}Expected Result{5}'{6} {0}' {1} toward {3} {4} of page contains text '{2}'{5}{5}", inputLabel, elementType, inputValue, elementYPosition, elementXPosition, Environment.NewLine, user)); } else { stepsList.AppendText(string.Format("{3}Expected Result{3}{4} '{0}' {1} contains text '{2}'{3}{3}", inputLabel, elementType, inputValue, Environment.NewLine, user)); } } else { elementType = "Button"; mshtml.IHTMLInputButtonElement inputButton = element.DomElement as mshtml.IHTMLInputButtonElement; //need to clean up - check if field is a password field! if (input.type.ToLower() == "password") { elementType = "Input"; } // Check if the selected element has an associated label we can use var inputLabel = ""; var inputLabels = browser.Document.GetElementsByTagName("label"); foreach (HtmlElement lbl in inputLabels) { //check if element has an ID so we can obtain a label for it if (element.Id != null) { //check if the current label for attribute matches one for our element String forLabel = lbl.OuterHtml.Replace("\"", ""); if (forLabel.Contains("for=" + element.Id)) { inputLabel = lbl.OuterText; } } } string inputValue = ""; if (input.value == null) { inputValue = input.name; } else { inputValue = input.value; } if (RecordElementPosition == true) { stepsList.AppendText(string.Format("{4}Expected Result{4}{5} {0} toward {2} {3} of page contains text '{1}'{4}{4}", elementType, inputValue, elementYPosition, elementXPosition, Environment.NewLine, user.ToUpper())); } else { // stepsList.AppendText(string.Format("Expected Result{2}{3} {0} contains text '{1}'{2}{2}", elementType, inputValue, Environment.NewLine, user)); if (inputLabel == "") { inputLabel = input.name; } stepsList.AppendText(string.Format("{3}Expected Result{3}{4} '{0}' {1} contains text '{2}'{3}{3}", inputLabel, elementType, inputValue, Environment.NewLine, user)); } } } catch { } elementType = "Input"; break; case "button": elementType = "Button"; mshtml.IHTMLElement button = element.DomElement as mshtml.IHTMLElement; if (RecordElementPosition == true) { stepsList.AppendText(string.Format("{4}Expected Result{4}{5} {0} toward {2} {3} of page contains text '{1}'{4}{4}", elementType, button.innerHTML, elementYPosition, elementXPosition, Environment.NewLine, user)); } else { stepsList.AppendText(string.Format("{2}Expected Result{2}{3} {0} contains text '{1}'{2}{2}", elementType, button.innerHTML, Environment.NewLine, user)); } break; case "select": elementType = "Select list"; mshtml.IHTMLSelectElement select = element.DomElement as mshtml.IHTMLSelectElement; mshtml.HTMLOptionElement option = (mshtml.HTMLOptionElement)select.item(select.selectedIndex, null); // use select list associated label name // Check if the selected element has an associated label we can use var elementLabel = ""; var labels = browser.Document.GetElementsByTagName("label"); foreach (HtmlElement lbl in labels) { //check if element has an ID so we can obtain a label for it if (element.Id != null) { //check if the current label for attribute matches one for our element String forLabel = lbl.OuterHtml.Replace("\"", ""); if (forLabel.Contains("for=" + element.Id)) { elementLabel = lbl.OuterText; } } } var selectValue = ""; if (select.selectedIndex != 0) { selectValue = option.text; } if (selectValue != "") { if (RecordElementPosition == true) { stepsList.AppendText(string.Format("{5}Expected Result{5}{6} '{0}' {1} toward {3} {4} of page contains option '{2}'{5}{5}", elementLabel, elementType, selectValue, elementYPosition, elementXPosition, Environment.NewLine, user)); stepsList.AppendText("\n"); } else { stepsList.AppendText(string.Format("{3}Expected Result{3}{4} '{0}' {1} contains option '{2}'{3}{3}", elementLabel, elementType, selectValue, Environment.NewLine, user)); stepsList.AppendText("\n"); } } break; } ScrollToRecordedStepsEnd(); }