Я использую Watin для получения данных со страницы синхронизации паролей.Я ожидал, что значения будут возвращены.Может быть нулевым, если значение было (в коде HTML).
Но я получаю нечто более неожиданное
{string[4, 4]}
[0, 0] = null
[0, 1] = "MAINFRAME"
[0, 2] = "DOMAIN"
[0, 3] = "WebClient"
[1, 0] = null
[1, 1] = "INTERNALID"
[1, 2] = "FIRSTNAME.LASTNAME"
[1, 3] = "INTERNALID"
[2, 0] = null
[2, 1] = "Yes"
[2, 2] = "Yes"
[2, 3] = "Yes"
[3, 0] = null
[3, 1] = ""
[3, 2] = ""
[3, 3] = ""
HTML-код выглядит как
<TABLE WIDTH="100%" CELLSPACING=0 CELLPADDING=5 BORDER=0 class="TABLEBORDER">
<TR>
<TH class=HEADTEXT>
Target
</TH>
<TH class=HEADTEXT>
Trigger<br>enabled?
</TH>
<TH class=HEADTEXT>
Account
</TH>
<TH class=HEADTEXT>
Password<br>changed?
</TH>
<TH class=HEADTEXT>
Error message<br>(if any)
</TH>
<!-- S_STATUS_ROW -->
<TR>
<TD valign=top class=CELLTEXT>
MAINFRAME
</TD>
<TD valign=top class=CELLTEXT>
No
</TD>
<TD valign=top class=CELLTEXT>
INTERNALID
</TD>
<TD valign=top class=CELLTEXT>
Yes
</TD>
<TD valign=top class=CELLTEXT>
</TD>
<!-- S_STATUS_ROW -->
<TR>
<TD valign=top class=CELLTEXT>
DOMAIN
</TD>
<TD valign=top class=CELLTEXT>
No
</TD>
<TD valign=top class=CELLTEXT>
FIRSTNAME.LASTNAME
</TD>
<TD valign=top class=CELLTEXT>
Yes
</TD>
<TD valign=top class=CELLTEXT>
</TD>
<!-- S_STATUS_ROW -->
<TR>
<TD valign=top class=CELLTEXT>
WebClient
</TD>
<TD valign=top class=CELLTEXT>
No
</TD>
<TD valign=top class=CELLTEXT>
INTERNALID
</TD>
<TD valign=top class=CELLTEXT>
Yes
</TD>
<TD valign=top class=CELLTEXT>
</TD>
<!-- S_STATUS_CONTENT_BOTTOM -->
</TABLE>
И, наконец, вот код C #.
String path = "http://localhost/cgi.exe?ID=" + userName;
Int32 startingRow = 1;
using (var browser = new IE(path))
{
try
{
browser.Image(Find.ByAlt("Use a password")).Click();
browser.TextField(Find.ByName("_MYPW")).TypeText(privateCurrentPassword);
browser.Image(Find.ByAlt("Verify password")).Click();
browser.Link(Find.ByTitle("Change passwords")).Click();
browser.TextField(Find.ByName("_NEWP1")).TypeText(privateNewPassword);
browser.TextField(Find.ByName("_NEWP2")).TypeText(privateNewPassword);
browser.Image(Find.ByName("SUBMIT-CHANGE")).Click();
Table table = browser.Table(Find.ByClass("TABLEBORDER"));
Int32 numberOfColumn = table.TableRows[startingRow].TableCells.Count;
Int32 currentRow = startingRow;
td1stcolumn = new String[table.OwnTableRows.Count];
td2ndcolumn = new String[table.OwnTableRows.Count];
td3rdcolumn = new String[table.OwnTableRows.Count];
td4thcolumn = new String[table.OwnTableRows.Count];
for (int i = 1; i < table.OwnTableRows.Count; i++)
{
td1stcolumn[i] = table.OwnTableRows[i].TableCells[0].Text.Trim();
td2ndcolumn[i] = table.OwnTableRows[i].TableCells[2].Text.Trim();
td3rdcolumn[i] = table.OwnTableRows[i].TableCells[3].Text.Trim();
td4thcolumn[i] = table.OwnTableRows[i].TableCells[4].Text.Trim();
}
String[,] arrayOfStrings = new String[4,td1stcolumn.Length];
for(int j = 0; j < td1stcolumn.Length; j++)
{
arrayOfStrings[0,j] = td1stcolumn[j];
arrayOfStrings[1,j] = td2ndcolumn[j];
arrayOfStrings[2,j] = td3rdcolumn[j];
arrayOfStrings[3,j] = td4thcolumn[j];
}
string resultDialogString = ResultDialog.ShowBox(arrayOfStrings, "Result Page", passwordTextBox.Text.ToString().Trim());
}
catch (ElementNotFoundException enfe)
{
String error = enfe.Message.ToString();
browser.TextField(Find.ByName("_MYPW")).TypeText(privateCurrentPassword);
browser.Image(Find.ByAlt("Verify password")).Click();
browser.Link(Find.ByTitle("Change passwords")).Click();
browser.TextField(Find.ByName("_NEWP1")).TypeText(privateNewPassword);
browser.TextField(Find.ByName("_NEWP2")).TypeText(privateNewPassword);
browser.Image(Find.ByName("SUBMIT-CHANGE")).Click();
Table table = browser.Table(Find.ByClass("TABLEBORDER"));
Int32 numberOfColumn = table.TableRows[startingRow].TableCells.Count;
Int32 currentRow = startingRow;
td1stcolumn = new String[table.OwnTableRows.Count];
td2ndcolumn = new String[table.OwnTableRows.Count];
td3rdcolumn = new String[table.OwnTableRows.Count];
td4thcolumn = new String[table.OwnTableRows.Count];
for (int i = 1; i < table.OwnTableRows.Count; i++)
{
td1stcolumn[i] = table.OwnTableRows[i].TableCells[0].Text.Trim();
td2ndcolumn[i] = table.OwnTableRows[i].TableCells[2].Text.Trim();
td3rdcolumn[i] = table.OwnTableRows[i].TableCells[3].Text.Trim();
td4thcolumn[i] = table.OwnTableRows[i].TableCells[4].Text.Trim();
}
String[,] arrayOfStrings = new String[4, td1stcolumn.Length];
for (int j = 0; j < td1stcolumn.Length; j++)
{
arrayOfStrings[0, j] = td1stcolumn[j];
arrayOfStrings[1, j] = td2ndcolumn[j];
arrayOfStrings[2, j] = td3rdcolumn[j];
arrayOfStrings[3, j] = td4thcolumn[j];
}
string resultDialogString = ResultDialog.ShowBox(arrayOfStrings, "Result Page", passwordTextBox.Text.ToString().Trim());
}
}