FAQ
General issues
Section «Tasks»
General information
The project consists of two files, "Program.cs" - with the project code, and "TaskProject.csproj" - for opening it in Visual Studio.
The file header contains commented out system xml tags that contain metadata and are necessary for proper operation.
The file header contains commented out system xml tags that contain metadata and are necessary for proper operation.
- name - project name.
- version - version of the project.
- description - description of the project.
- references - links to third-party dlls.
Launch of the project
In the registrar, in the "Jobs" section, select your "Program.cs" file.
Launching the Development Environment
In the registrar, section "Tasks", export the project to a new folder and run the file "TaskProject.csproj" (in Visual Studio). This is a minimal project, on the basis of which you can make your own.
If you have a dll that needs to be added to the project:
If you have a dll that needs to be added to the project:
- add a reference to it in Visual Studio.
- in the <references> block, specify the file name or full path (each dll on a new line).
- copy the dll to the project folder or to "%appdata%\Staf4 Registrator\Assemblies\" (if you specified the full path above, you do not need to copy the file).
Declared variables
Data string received in case of selecting the "Data from file" mode of operation:
public string data = null;
Settings object, available keys:
- AnticaptchaAttemptsEnterCaptcha - number of attempts to enter captcha.
- DataDir - program data folder.
- TempDir - folder of temporary program files (captchas).
- ResultsDir - folder of program results.
- ProjectDir - current project folder.
public Dictionary<string, string> settings;
Current proxy object (type, ip, port, login...):
public Staf4.Proxy proxy;
Current user profile object (email, login, password, full name...):
public Staf4.Profile profile;
Object of work with the anti-captcha service:
public Staf4.NsAnticaptcha.Anticaptcha anticaptcha;
Object of work with SMS service:
public Staf4.NsSms.Sms sms;
Object for executing http requests:
public Staf4.NsCurl.ICurl http;
Browser operation object (via Selenium):
public Staf4.SeleniumJs browser;
Script result object:
- bool Success - result of script execution (true - success, false - error).
- string Data - data returned to the program in case of successful execution of the script.
- string Error - error text, in case of unsuccessful script execution.
- Log(string) - output a string to the log.
public Staf4.TaskResult result;
Input data, proxy, profile
Displaying a dialog with input data, current proxy and user profile:
MessageBox.Show(String.Format("Data: {0}\r\n\r\nProxy: {1}\r\n\r\nProfile: {2}", data, proxy, profile));
Anticaptcha service (http requests)
Balance request:
AnticaptchaGetBalanceResult acBalance = anticaptcha.GetBalance();
MessageBox.Show(String.Format("Result: {0}\r\nText: {1} {2}", acBalance.Result, acBalance.ResultExt, anticaptcha.Currency));
Solving a captcha-image (+ an example of the implementation of captcha input several attempts):
string urlCaptcha = "https://debug.registrator.pl/captcha/";
CurlResult respCapImg1 = http.Get(urlCaptcha);
string matchImg = ParseSt.PregMatchSingle(respCapImg1.Data, "<img id=\"image\" src=\"([^\"]+)\"");
int captchaEnterCnt = 0;
CAPTCHA:
captchaEnterCnt++;
string captchaFilePath1 = GetTempFileName("png", "captcha");
respCapImg1 = http.SaveFile("https://debug.registrator.pl/captcha/" + matchImg, "", "", "", captchaFilePath1);
if (respCapImg1.CodeInt == 404) { result.Error = "error_captcha_down"; return; }
AnticaptchaRecognizeResult captchaRecognizedImg1 = anticaptcha.Recognize(captchaFilePath1);
if (captchaRecognizedImg1.Result != AnticaptchaResultEnum.ok_rec)
{
if (captchaEnterCnt < ConverterSt.String2int32(settings["AnticaptchaAttemptsEnterCaptcha"])) { goto CAPTCHA; }
result.Error = "error_anticaptcha"; return;
}
http.PostAddDataString("captcha=" + captchaRecognizedImg1.ResultExt, "application/x-www-form-urlencoded");
respCapImg1 = http.Get(urlCaptcha);
string matchResultCapImg1 = ParseSt.PregMatchSingle(respCapImg1.Data, "<span id=\"result\">(.*?)</span>");
if (matchResultCapImg1 == "wrong")
{
if (captchaEnterCnt < ConverterSt.String2int32(settings["AnticaptchaAttemptsEnterCaptcha"])) { goto CAPTCHA; }
}
switch (matchResultCapImg1)
{
case "ok": result.Success = true; break;
case "wrong": result.Error = "error_captcha_wrong"; break;
default: result.Error = "error_unknown_reason"; break;
}
Solving reCaptcha2:
AnticaptchaRecognizeResult captchaRecognizedRc21 = anticaptcha.RecognizeRecaptcha2("6LefM7kjAAAAAGxc8ujU0Udr_2LrmzGbp3tf93jV", "https://debug.registrator.pl/", false, false);
if (captchaRecognizedRc21.Result != AnticaptchaResultEnum.ok_rec) { result.Error = "error_anticaptcha"; return; }
http.PostAddDataString("g-recaptcha-response=" + captchaRecognizedRc21.ResultExt, "application/x-www-form-urlencoded");
CurlResult respCapRc21 = http.Get("https://debug.registrator.pl/recaptcha2/");
string matchResultCapRc21 = ParseSt.PregMatchSingle(respCapRc21.Data, "<span id=\"result\">(.*?)</span>");
switch (matchResultCapRc21)
{
case "ok": result.Success = true; break;
case "error": result.Error = "error_captcha_wrong"; break;
default: result.Error = "error_unknown_reason"; break;
}
Solving reCaptcha3:
AnticaptchaRecognizeResult captchaRecognizedRc31 = anticaptcha.RecognizeRecaptcha3("6LeiM7kjAAAAAPV38BbKfNlFSfwYRRjE8Y32WgBb", "https://debug.registrator.pl/", "actionName", "0.3", false);
if (captchaRecognizedRc31.Result != AnticaptchaResultEnum.ok_rec) { result.Error = "error_anticaptcha"; return; }
http.PostAddDataString("g-recaptcha-response=" + captchaRecognizedRc31.ResultExt, "application/x-www-form-urlencoded");
CurlResult respCapRc31 = http.Get("https://debug.registrator.pl/recaptcha3/");
string matchResultCapRc31 = ParseSt.PregMatchSingle(respCapRc31.Data, "<span id=\"result\">(.*?)</span>");
switch (matchResultCapRc31)
{
case "ok": result.Success = true; break;
case "error": result.Error = "error_captcha_wrong"; break;
default: result.Error = "error_unknown_reason"; break;
}
Solving hCaptcha:
AnticaptchaRecognizeResult captchaRecognizedHc1 = anticaptcha.RecognizeHCaptcha("41079ab2-62e6-42cb-8177-0e290214ae92", "https://debug.registrator.pl/");
if (captchaRecognizedHc1.Result != AnticaptchaResultEnum.ok_rec) { result.Error = "error_anticaptcha"; return; }
http.PostAddDataString("h-captcha-response=" + captchaRecognizedHc1.ResultExt, "application/x-www-form-urlencoded");
CurlResult respCapHc1 = http.Get("https://debug.registrator.pl/hcaptcha/");
string matchResultCapHc1 = ParseSt.PregMatchSingle(respCapHc1.Data, "<span id=\"result\">(.*?)</span>");
switch (matchResultCapHc1)
{
case "ok": result.Success = true; break;
case "error": result.Error = "error_captcha_wrong"; break;
default: result.Error = "error_unknown_reason"; break;
}
Solving Turnstile:
AnticaptchaRecognizeResult captchaRecognizedTr1 = anticaptcha.RecognizeTurnstile("0x4AAAAAAAB5SzQ_eELDE-99", "https://debug.registrator.pl/");
if (captchaRecognizedTr1.Result != AnticaptchaResultEnum.ok_rec) { result.Error = "error_anticaptcha"; return; }
http.PostAddDataString("h-captcha-response=" + captchaRecognizedTr1.ResultExt, "application/x-www-form-urlencoded");
CurlResult respCapTr1 = http.Get("https://debug.registrator.pl/turnstile/");
string matchResultCapTr1 = ParseSt.PregMatchSingle(respCapTr1.Data, "<span id=\"result\">(.*?)</span>");
switch (matchResultCapTr1)
{
case "ok": result.Success = true; break;
case "error": result.Error = "error_captcha_wrong"; break;
default: result.Error = "error_unknown_reason"; break;
}
Solving YandexSmartCaptcha:
AnticaptchaRecognizeResult captchaRecognizedYc1 = anticaptcha.RecognizeYandexSmartCaptcha("fxBXzFpewqTQccxRvug1hlaySSqgP2BCF8nKnzc5", "https://debug.registrator.pl/");
if (captchaRecognizedYc1.Result != AnticaptchaResultEnum.ok_rec) { result.Error = "error_anticaptcha"; return; }
http.PostAddDataString("h-captcha-response=" + captchaRecognizedYc1.ResultExt, "application/x-www-form-urlencoded");
CurlResult respCapYc1 = http.Get("https://debug.registrator.pl/yasmartcaptcha/");
string matchResultCapYc1 = ParseSt.PregMatchSingle(respCapYc1.Data, "<span id=\"result\">(.*?)</span>");
switch (matchResultCapYc1)
{
case "ok": result.Success = true; break;
case "error": result.Error = "error_captcha_wrong"; break;
default: result.Error = "error_unknown_reason"; break;
}
Anticaptcha service (browser)
Solving a captcha-image:
if (!browser.ServerStart()) { result.Error = "browser_start_error"; return; }
string captchaFilePath2 = GetTempFileName("jpg", "captcha");
browser.ProxyServer.ResponseEvent += async delegate (Titanium.Web.Proxy.EventArguments.SessionEventArgs __e)
{
if (ParseSt.PregMatchBool(__e.HttpClient.Request.Url, "/captcha/([0-9]+)\.png"))
{
byte[] body = await __e.GetResponseBody();
File.WriteAllBytes(captchaFilePath2, body);
}
return __e;
};
browser.PageOpen("https://debug.registrator.pl/captcha/");
AnticaptchaRecognizeResult captchaRecognizedImg2 = anticaptcha.Recognize(captchaFilePath2);
if (captchaRecognizedImg2.Result != AnticaptchaResultEnum.ok_rec) { result.Error = "error_anticaptcha"; return; }
browser.TextInElement(By.CssSelector("input[name=captcha]"), captchaRecognizedImg2.ResultExt);
browser.ClickOnElement(By.Id("submit"));
browser.LoadingFrameWait(500);
string matchResultCapImg2 = ParseSt.PregMatchSingle(browser.GetPageContent(), "<span id=\"result\">(.*?)</span>");
switch (matchResultCapImg2)
{
case "ok": result.Success = true; break;
case "wrong": result.Error = "error_captcha_wrong"; break;
default: result.Error = "error_unknown_reason"; break;
}
Solving reCaptcha2:
if (!browser.ServerStart()) { result.Error = "browser_start_error"; return; }
browser.RecaptchaReplace(true);
browser.PageOpen("https://debug.registrator.pl/recaptcha2/");
AnticaptchaRecognizeResult captchaRecognizedRc22 = anticaptcha.RecognizeRecaptcha2("6LefM7kjAAAAAGxc8ujU0Udr_2LrmzGbp3tf93jV", "https://debug.registrator.pl/", false, false);
if (captchaRecognizedRc22.Result != AnticaptchaResultEnum.ok_rec) { result.Error = "error_anticaptcha"; return; }
browser.JsExec("window.grecaptcha.setResponse(\"" + captchaRecognizedRc22.ResultExt + "\");");
browser.ClickOnElement(By.Id("submit"));
browser.LoadingFrameWait(500);
string matchResultCapRc22 = ParseSt.PregMatchSingle(browser.GetPageContent(), "<span id=\"result\">(.*?)</span>");
switch (matchResultCapRc22)
{
case "ok": result.Success = true; break;
case "error": result.Error = "error_captcha_wrong"; break;
default: result.Error = "error_unknown_reason"; break;
}
Solving reCaptcha3:
if (!browser.ServerStart()) { result.Error = "browser_start_error"; return; }
browser.RecaptchaReplace(true);
browser.PageOpen("https://debug.registrator.pl/recaptcha3/");
AnticaptchaRecognizeResult captchaRecognizedRc32 = anticaptcha.RecognizeRecaptcha3("6LeiM7kjAAAAAPV38BbKfNlFSfwYRRjE8Y32WgBb", "https://debug.registrator.pl/", "actionName", "0.3", false);
if (captchaRecognizedRc32.Result != AnticaptchaResultEnum.ok_rec) { result.Error = "error_anticaptcha"; return; }
browser.JsExec("window.grecaptcha.setResponseExecute(\"" + captchaRecognizedRc32.ResultExt + "\");");
browser.ClickOnElement(By.Id("submit"));
browser.LoadingFrameWait(500);
string matchResultCapRc32 = ParseSt.PregMatchSingle(browser.GetPageContent(), "<span id=\"result\">(.*?)</span>");
switch (matchResultCapRc32)
{
case "ok": result.Success = true; break;
case "error": result.Error = "error_captcha_wrong"; break;
default: result.Error = "error_unknown_reason"; break;
}
Solving hCaptcha:
if (!browser.ServerStart()) { result.Error = "browser_start_error"; return; }
browser.HcaptchaReplace(true);
browser.PageOpen("https://debug.registrator.pl/hcaptcha/");
AnticaptchaRecognizeResult captchaRecognizedHc2 = anticaptcha.RecognizeHCaptcha("41079ab2-62e6-42cb-8177-0e290214ae92", "https://debug.registrator.pl/");
if (captchaRecognizedHc2.Result != AnticaptchaResultEnum.ok_rec) { result.Error = "error_anticaptcha"; return; }
browser.JsExec("window.hcaptcha.setResponse(\"" + captchaRecognizedHc2.ResultExt + "\");");
browser.ClickOnElement(By.Id("submit"));
browser.LoadingFrameWait(500);
string matchResultCapHc2 = ParseSt.PregMatchSingle(browser.GetPageContent(), "<span id=\"result\">(.*?)</span>");
switch (matchResultCapHc2)
{
case "ok": result.Success = true; break;
case "error": result.Error = "error_captcha_wrong"; break;
default: result.Error = "error_unknown_reason"; break;
}
Solving Turnstile:
if (!browser.ServerStart()) { result.Error = "browser_start_error"; return; }
browser.TurnstileReplace(true);
browser.PageOpen("https://debug.registrator.pl/turnstile/");
AnticaptchaRecognizeResult captchaRecognizedTr2 = anticaptcha.RecognizeTurnstile("0x4AAAAAAAB5SzQ_eELDE-99", "https://debug.registrator.pl/");
if (captchaRecognizedTr2.Result != AnticaptchaResultEnum.ok_rec) { result.Error = "error_anticaptcha"; return; }
browser.JsExec("window.turnstile.setResponse(\"" + captchaRecognizedTr2.ResultExt + "\");");
browser.ClickOnElement(By.Id("submit"));
browser.LoadingFrameWait(500);
string matchResultCapTr2 = ParseSt.PregMatchSingle(browser.GetPageContent(), "<span id=\"result\">(.*?)</span>");
switch (matchResultCapTr2)
{
case "ok": result.Success = true; break;
case "error": result.Error = "error_captcha_wrong"; break;
default: result.Error = "error_unknown_reason"; break;
}
Solving YandexSmartCaptcha:
if (!browser.ServerStart()) { result.Error = "browser_start_error"; return; }
browser.YandexSmartCaptchaReplace(true);
browser.PageOpen("https://debug.registrator.pl/yasmartcaptcha/");
AnticaptchaRecognizeResult captchaRecognizedYc2 = anticaptcha.RecognizeYandexSmartCaptcha("fxBXzFpewqTQccxRvug1hlaySSqgP2BCF8nKnzc5", "https://debug.registrator.pl/");
if (captchaRecognizedYc2.Result != AnticaptchaResultEnum.ok_rec) { result.Error = "error_anticaptcha"; return; }
browser.JsExec("window.smartCaptcha.setResponse(\"" + captchaRecognizedYc2.ResultExt + "\");");
browser.ClickOnElement(By.Id("submit"));
browser.LoadingFrameWait(500);
string matchResultCapYc2 = ParseSt.PregMatchSingle(browser.GetPageContent(), "<span id=\"result\">(.*?)</span>");
switch (matchResultCapYc2)
{
case "ok": result.Success = true; break;
case "error": result.Error = "error_captcha_wrong"; break;
default: result.Error = "error_unknown_reason"; break;
}
SMS service
Balance request:
SmsSharedResult smsBalance = sms.GetBalance();
MessageBox.Show(String.Format("Result: {0}\r\nText: {1} {2}", smsBalance.Result, smsBalance.ResultExt, sms.Currency));
Phone and SMS request:
sms.Service = SmsServiceEnum.MailRu;
SmsGetPhoneResult smsPhone = sms.GetPhone();
if (smsPhone.Result == SmsResultEnum.ok)
{
SmsSharedResult smsSms = sms.GetSms();
MessageBox.Show(String.Format("SMS-Service: {0}\r\nService: {1}\r\n\r\nPhone: {2}\r\n\r\nSms: {3}", sms.ServiceName, sms.Service, smsPhone, smsSms));
}
else
{
MessageBox.Show(String.Format("SMS-Service: {0}\r\nService: {1}\r\n\r\nPhone: {2}", sms.ServiceName, sms.Service, smsPhone));
}
Making http requests
Get request:
CurlResult resp1 = http.Get("https://chek.zennolab.com/proxy.php");
MessageBox.Show(resp1.Data);
Post request + cookie setting:
http.CookieAdd("param1", "cookieVal");
http.PostAddDataString("param1=postVal1¶m2=postVal2", "application/x-www-form-urlencoded");
CurlResult resp2 = http.Get("https://chek.zennolab.com/proxy.php", "http://referer.test");
MessageBox.Show(resp2.Data);
Downloading and sending a file:
string tempFilePath = GetTempFileName("png", "captcha");
CurlResult resp3 = http.SaveFile("https://debug.registrator.pl/captcha/111.png", "", "", "", tempFilePath);
http.PostAddFile("111.png", tempFilePath);
resp3 = http.Get("https://chek.zennolab.com/proxy.php", "http://referer.test");
MessageBox.Show(tempFilePath + "\r\n\r\n" + resp3.Data);
Working with the browser
Enabling the internal proxy, launching the browser, and setting the data input rate:
browser.Proxification = true;
if (!browser.ServerStart()) { result.Error = "browser_start_error"; return; }
browser.UserSpeed = SeleniumJs.UserSpeedEnum.Realtime;
Setting up an internal proxy (caching):
browser.ProxyServer.CacheAdd(HttpsProxyServerTitanium.FilterOptions.Css | HttpsProxyServerTitanium.FilterOptions.Javascript | HttpsProxyServerTitanium.FilterOptions.Images | HttpsProxyServerTitanium.FilterOptions.Fonts);
Page opening:
browser.PageOpen("https://debug.registrator.pl/selenium/");
Waiting for frames to load with a pause:
browser.LoadingFrameWait(500);
Finding an element and entering text:
var elmInput = browser.FindElement(By.Id("input1"));
if (elmInput != null) { browser.TextInElement(elmInput, "New demo text"); }
Search for one of several elements:
var elmInput2 = browser.FindElementAnyFromArray(new By[] { By.Id("input0"), By.Id("input1") }, 1);
if (elmInput2 != null) { browser.TextInElement(elmInput, " Add text"); }
Clearing text in an element:
browser.TextClearInElement(By.CssSelector("#form #input2"));
browser.TextInElement(By.CssSelector("#form #input2"), "New demo text 2");
Selectbox:
browser.ClickOnSelectOption(By.Id("select1"), "1");
Click on an element:
browser.ClickOnElement(By.XPath("//input[@type='checkbox'][@id='checkbox1']"));
Downloading a picture (taken as a screenshot):
string imgDownloadFilePath = GetTempFileName("png", "image");
browser.ImageDownload(imgDownloadFilePath, By.Id("image2"));
MessageBox.Show("Image download path: " + imgDownloadFilePath);
Getting the coordinates and size of an element:
int imgPosX1, imgPosY1, imgPosX2, imgPosY2, imgPosWidth, imgPosHeight;
imgPosX1 = imgPosY1 = imgPosX2 = imgPosY2 = imgPosWidth = imgPosHeight = 0;
browser.GetElementPosition(By.Id("image1"), ref imgPosX1, ref imgPosY1, ref imgPosX2, ref imgPosY2, ref imgPosWidth, ref imgPosHeight);
MessageBox.Show(String.Format("Image info:\r\nPosition X1: {0}\r\nPosition Y1: {1}\r\nPosition X2: {2}\r\nPosition Y2: {3}\r\nWidth: {4}\r\nHeight: {5}", imgPosX1, imgPosY1, imgPosX2, imgPosY2, imgPosWidth, imgPosHeight));
Mouse movement to coordinates:
browser.MouseMoveToCoords(50, 300);
Mouse movement to an element:
browser.MouseMoveToElement(By.Id("image1"));
Move the mouse over an element:
browser.MouseMoveAroundElement(By.Id("image2"));
Switching focus to the specified frame (+ searching for an element in it):
browser.SwitchToFrame(0);
MessageBox.Show("Element in frame: " + (browser.ElementExists(By.Id("inputInFrame1")) ? "finded" : "not finded"));
Switching focus to the main frame:
browser.SwitchToMainWindow();
Executing a js script on a page:
browser.JsExec("$('#submit').removeClass('btn-primary').addClass('btn-danger');");
Mouse move to coordinates and click (+ get element coordinates):
int chbPosX1, chbPosY1, chbPosX2, chbPosY2, chbPosWidth, chbPosHeight;
chbPosX1 = chbPosY1 = chbPosX2 = chbPosY2 = chbPosWidth = chbPosHeight = 0;
browser.GetElementPosition(By.Id("checkbox2"), ref chbPosX1, ref chbPosY1, ref chbPosX2, ref chbPosY2, ref chbPosWidth, ref chbPosHeight);
browser.FullEmulation_MouseClickToCoords(chbPosX1 + 5, chbPosY1 + 5);
Moving the mouse to an element and clicking on the selector item:
browser.FullEmulation_ClickOnSelectOption(By.Id("select2"), "3");
Mouse movement to the element and its filling (for text fields):
browser.FullEmulation_MouseAndFill(By.Id("textarea1"), "New demo text, line 1\r\nNew demo text, line 2");
Moving the mouse to an element and clicking on it:
browser.FullEmulation_MouseClickToElement(By.Id("checkbox3"));
Pause:
browser.Sleep(500);
Getting url and page content:
MessageBox.Show("Page url: " + browser.GetPageUrl() + "\r\n\r\nPage content:\r\n" + browser.GetPageContent().Replace("\r\n", "").Replace("\t", ""));
Checking for the absence of an element:
var elmAbsentTest = browser.ElementAbsent(By.Id("elmAbsent"), 1);
var elmAbsentTest2 = !browser.ElementAbsent(By.Id("elmInvis"), 1);
Checking for the absence of an element or its invisibility:
var elmAbsentInvisTest = browser.ElementAbsentOrInvisible(By.Id("elmAbsent"), 1);
var elmAbsentInvisTest2 = browser.ElementAbsentOrInvisible(By.Id("elmInvis"), 1);
var elmAbsentInvisTest3 = !browser.ElementAbsentOrInvisible(By.Id("elmVis"), 1);
Checking for the existence of an element:
var elmExistsTest = browser.ElementExists(By.Id("elmVis"), 1);
var elmExistsTest2 = browser.ElementExists(By.Id("elmInvis"), 1);
var elmExistsTest3 = !browser.ElementExists(By.Id("elmAbsent"), 1);
browser.ClickOnElement(By.Id("btnAbsentToCreate"));
var elmExistsTest4 = browser.ElementExists(By.Id("elmAbsentToCreate"), 3);
Checking the existence of an element and its visibility:
var elmExistsVisTest = browser.ElementExistsAndVisible(By.Id("elmVis"), 1);
var elmExistsVisTest2 = !browser.ElementExistsAndVisible(By.Id("elmInvis"), 1);
var elmExistsVisTest3 = !browser.ElementExistsAndVisible(By.Id("elmAbsent"), 1);
browser.ClickOnElement(By.Id("btnInvisToVis"));
var elmExistsVisTest4 = browser.ElementExistsAndVisible(By.Id("elmInvisToVis"), 3);
Checking the presence and subsequent absence of an element (appeared-disappeared):
browser.ClickOnElement(By.Id("btnInvisToVisToInvis"));
var elmExistsAbsentTest = !browser.ElementExistsAbsent(By.Id("elmInvisToVisToInvis"), 4, 4);
browser.ClickOnElement(By.Id("btnAbsentToCreateToAbsent"));
var elmExistsAbsentTest2 = browser.ElementExistsAbsent(By.Id("elmAbsentToCreateToAbsent"), 4, 4);
Checking for the existence of an element and its visibility, and then checking for the absence of an element or its invisibility (appeared-disappeared):
browser.ClickOnElement(By.Id("btnInvisToVisToInvis"));
var elmExistsVisAbsentInvisTest = browser.ElementExistsAndVisible2AbsentOrInvisible(By.Id("elmInvisToVisToInvis"), 4, 4);
browser.ClickOnElement(By.Id("btnAbsentToCreateToAbsent"));
var elmExistsVisAbsentInvisTest2 = browser.ElementExistsAndVisible2AbsentOrInvisible(By.Id("elmAbsentToCreateToAbsent"), 4, 4);
Checking for the existence of one of several elements:
var elmExistsAnyFromArray = browser.ElementExistsAnyFromArray(new By[] { By.Id("input0"), By.Id("input1") }, 1);
Element existence/visibility test results:
MessageBox.Show(String.Format("TESTS\r\n"
+ "Absent: {0}, {1}\r\n"
+ "Absent or Invisible: {2}, {3}, {4}\r\n"
+ "Exists: {5}, {6}, {7}, {8}\r\n"
+ "Exists and Visible: {9}, {10}, {11}, {12}\r\n"
+ "Exists to Absent: {13}, {14}\r\n"
+ "Exists and Visible to Absent or Invisible: {15}, {16}\r\n"
+ "Exists any from array: {17}\r\n",
elmAbsentTest, elmAbsentTest2,
elmAbsentInvisTest, elmAbsentInvisTest2, elmAbsentInvisTest3,
elmExistsTest, elmExistsTest2, elmExistsTest3, elmExistsTest4,
elmExistsVisTest, elmExistsVisTest2, elmExistsVisTest3, elmExistsVisTest4,
elmExistsAbsentTest, elmExistsAbsentTest2,
elmExistsVisAbsentInvisTest, elmExistsVisAbsentInvisTest2,
elmExistsAnyFromArray
));
Additional Methods
Getting a temporary captcha file name for downloading and subsequent recognition:
GetTempFileName("png", "captcha")
Proxy ban - to move the current proxy to the banned list and log:
ProxyBanIp();
Long-term proxy ban - to move the current proxy to the list of long-term banned and log:
ProxyLongbanIp();
Dead proxy - to move the current proxy to the list of dead ones and log:
ProxyDeadIp();
Live proxy - to log the current proxy:
ProxyGoodIp();
Login is busy - to remove the login from the file (if used):
LoginBusy(profile.Login);
Result and logging
Logging:
result.Log("Debugging Data");
The result of the script (random: success / error):
result.Success = GeneratorSt.RandBool();
Success data:
result.Data = "Success, Thread #" + Thread.CurrentThread.Name;
Error text:
result.Error = "Error #" + GeneratorSt.Rand(1, 3);