- Регистрация
- 12.01.2011
- Сообщения
- 3 441
- Благодарностей
- 834
- Баллы
- 113
In this thread we will post samples of c# snippets
1 Alert with 2 buttons: "Yes" and "No":
Result is put to project's variable
1 - "Yes" was pressed
0 - "No" was pressed
-1 - "Close"
Link to the original post: http://zennolab.com/discussion/showthread.php?7860-Alert-C&p=45044&viewfull=1#post45044
2 Get last error:
This c# code has to be placed in bad end.
3 Complete all checkboxes on the page:
On the page all tags input:checkbox of active tag are filled with value from "CheckboxValue" ({-Variable.CheckboxValue-}).
"CheckboxValue" can be True or False.
4 Fill in all selects on the active tab page by last options:
It does work with classic select tags.
1 Alert with 2 buttons: "Yes" and "No":
Result is put to project's variable
1 - "Yes" was pressed
0 - "No" was pressed
-1 - "Close"
JavaScript:
// Show message
System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show("Press \"Yes\" or \"No\"", "Caption", System.Windows.Forms.MessageBoxButtons.YesNo);
// parse result
switch (result)
{
// if "Yes"
case System.Windows.Forms.DialogResult.Yes:
// here you can put your code
// or like this
return 1;
break;
// если нет
case System.Windows.Forms.DialogResult.No:
// here you can put your code
// or like this
return 0;
break;
// if something else, for instance DialogResult.Cancel
default:
// here you can put your code
// or like this
return -1;
break;
}
2 Get last error:
This c# code has to be placed in bad end.
JavaScript:
var error = project.GetLastError();
var tmp = "";
if(error != null)
tmp = string.Format("ActionComment: {0}.\r\nActionGroupId: {1}.\r\nActionId: {2}", error.ActionComment, error.ActionGroupId, error.ActionId);
return tmp;
On the page all tags input:checkbox of active tag are filled with value from "CheckboxValue" ({-Variable.CheckboxValue-}).
"CheckboxValue" can be True or False.
JavaScript:
// if page is not loaded yet, wait loading
if (instance.ActiveTab.IsBusy) instance.ActiveTab.WaitDownloading();
// find all checkbox on the page of active tab
HtmlElementCollection heCol = instance.ActiveTab.FindElementsByTags("input:checkbox");
// go through all checkboxes and fill them in
foreach(HtmlElement he in heCol.Elements)
{
// fill checkbox
he.SetValue(project.Variables["CheckboxValue"].Value, instance.EmulationLevel, false);
// emulation delay
instance.WaitFieldEmulationDelay();
}
It does work with classic select tags.
JavaScript:
// if page is not loaded yet, wait loading
if (instance.ActiveTab.IsBusy) instance.ActiveTab.WaitDownloading();
// find all selects on the page
HtmlElementCollection heCol = instance.ActiveTab.FindElementsByTags("select");
// go through all selects and fill them in
foreach(HtmlElement he in heCol.Elements)
{
// Find all options of select
HtmlElementCollection children = he.FindChildrenByTags("option");
// if there is any element
if (children.Count > 0)
{
// get last
HtmlElement c = children.Elements[children.Count-1];
// if element is not empty
if (!c.IsVoid)
{
// get element value
string outerText = c.GetAttribute("outertext");
// set value
he.SetSelectedItems(outerText);
// emulation delay
instance.WaitFieldEmulationDelay();
}
}
}
Последнее редактирование: