常問問題
一般问题
“任务”部分
一般信息
该项目由两个文件组成,“Program.cs” - 带有项目代码,以及“TaskProject.csproj” - 用于在 Visual Studio 中打开它。
文件头包含注释掉的系统 xml 标签,这些标签包含元数据并且是正确操作所必需的。
文件头包含注释掉的系统 xml 标签,这些标签包含元数据并且是正确操作所必需的。
- name - 项目名称。
- version - 项目的版本。
- description - 项目的描述。
- references - 第三方 dll 的链接。
启动项目
在注册器的“作业”部分中,选择您的“Program.cs”文件。
启动开发环境
在注册商的“任务”部分,将项目导出到新文件夹并运行文件“TaskProject.csproj”(在 Visual Studio 中)。 这是一个最小的项目,您可以在此基础上制作自己的项目。
如果你有一个dll需要添加到项目中:
如果你有一个dll需要添加到项目中:
- 在 Visual Studio 中添加对它的引用。
- 在 <references> 块中,指定文件名或完整路径(每个 dll 占一行)。
- 将 dll 复制到项目文件夹或“%appdata%\Staf4 Registrator\Assemblies\”(如果您在上面指定了完整路径,则不需要复制该文件)。
声明的变量
选择“来自文件的数据”操作模式时收到的数据字符串:
public string data = null;
设置对象,可用键:
- AnticaptchaAttemptsEnterCaptcha - 尝试输入验证码的次数。
- DataDir - 程序数据文件夹。
- TempDir - 临时程序文件(验证码)的文件夹。
- ResultsDir - 程序结果文件夹。
- ProjectDir - 当前项目文件夹。
public Dictionary<string, string> settings;
当前代理对象(类型、ip、端口、登录...):
public Staf4.Proxy proxy;
当前用户配置文件对象(电子邮件、登录名、密码、全名...):
public Staf4.Profile profile;
反验证码服务的工作对象:
public Staf4.NsAnticaptcha.Anticaptcha anticaptcha;
使用短信服务的对象:
public Staf4.NsSms.Sms sms;
执行http请求的对象:
public Staf4.NsCurl.ICurl http;
浏览器操作对象(通过Selenium):
public Staf4.SeleniumJs browser;
脚本结果对象:
- bool Success - 脚本执行的结果(true - 成功,false - 错误)。
- string Data - 脚本成功执行时返回给程序的数据。
- string Error - 脚本执行失败时的错误文本。
- Log(string) - 输出一个字符串到日志。
public Staf4.TaskResult result;
输入、代理、配置文件
显示包含输入数据、当前代理和用户配置文件的对话框:
MessageBox.Show(String.Format("Data: {0}\r\n\r\nProxy: {1}\r\n\r\nProfile: {2}", data, proxy, profile));
Anticaptcha 服务(http 请求)
余额要求:
AnticaptchaGetBalanceResult acBalance = anticaptcha.GetBalance();
MessageBox.Show(String.Format("Result: {0}\r\nText: {1} {2}", acBalance.Result, acBalance.ResultExt, anticaptcha.Currency));
解决验证码图像(+验证码输入的实施示例几次尝试):
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;
}
解决 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;
}
解决 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;
}
解决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;
}
解决旋转门:
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;
}
解决 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;
}
反验证码服务(浏览器)
解决验证码图像:
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;
}
解决 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;
}
解决 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;
}
解决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;
}
解决旋转门:
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;
}
解决 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;
}
短信服务
余额要求:
SmsSharedResult smsBalance = sms.GetBalance();
MessageBox.Show(String.Format("Result: {0}\r\nText: {1} {2}", smsBalance.Result, smsBalance.ResultExt, sms.Currency));
电话和短信要求:
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));
}
发起 http 请求
获取请求:
CurlResult resp1 = http.Get("https://chek.zennolab.com/proxy.php");
MessageBox.Show(resp1.Data);
发布请求 + cookie 设置:
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);
下载和发送文件:
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);
使用浏览器
启用内部代理,启动浏览器,并设置数据输入速率:
browser.Proxification = true;
if (!browser.ServerStart()) { result.Error = "browser_start_error"; return; }
browser.UserSpeed = SeleniumJs.UserSpeedEnum.Realtime;
设置内部代理(缓存):
browser.ProxyServer.CacheAdd(HttpsProxyServerTitanium.FilterOptions.Css | HttpsProxyServerTitanium.FilterOptions.Javascript | HttpsProxyServerTitanium.FilterOptions.Images | HttpsProxyServerTitanium.FilterOptions.Fonts);
页面打开:
browser.PageOpen("https://debug.registrator.pl/selenium/");
等待帧暂停加载:
browser.LoadingFrameWait(500);
查找元素并输入文本:
var elmInput = browser.FindElement(By.Id("input1"));
if (elmInput != null) { browser.TextInElement(elmInput, "New demo text"); }
搜索几个元素之一:
var elmInput2 = browser.FindElementAnyFromArray(new By[] { By.Id("input0"), By.Id("input1") }, 1);
if (elmInput2 != null) { browser.TextInElement(elmInput, " Add text"); }
清除元素中的文本:
browser.TextClearInElement(By.CssSelector("#form #input2"));
browser.TextInElement(By.CssSelector("#form #input2"), "New demo text 2");
选择框:
browser.ClickOnSelectOption(By.Id("select1"), "1");
单击一个元素:
browser.ClickOnElement(By.XPath("//input[@type='checkbox'][@id='checkbox1']"));
下载图片(截图):
string imgDownloadFilePath = GetTempFileName("png", "image");
browser.ImageDownload(imgDownloadFilePath, By.Id("image2"));
MessageBox.Show("Image download path: " + imgDownloadFilePath);
获取元素的坐标和大小:
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));
鼠标移动到坐标:
browser.MouseMoveToCoords(50, 300);
鼠标移动到一个元素:
browser.MouseMoveToElement(By.Id("image1"));
将鼠标移到一个元素上:
browser.MouseMoveAroundElement(By.Id("image2"));
将焦点切换到指定的框架(+ 在其中搜索元素):
browser.SwitchToFrame(0);
MessageBox.Show("Element in frame: " + (browser.ElementExists(By.Id("inputInFrame1")) ? "finded" : "not finded"));
将焦点切换到主框架:
browser.SwitchToMainWindow();
在页面上执行js脚本:
browser.JsExec("$('#submit').removeClass('btn-primary').addClass('btn-danger');");
鼠标移动到坐标点击(+获取元素坐标):
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);
将鼠标移动到一个元素并单击选择器项:
browser.FullEmulation_ClickOnSelectOption(By.Id("select2"), "3");
鼠标移动到元素及其填充(对于文本字段):
browser.FullEmulation_MouseAndFill(By.Id("textarea1"), "New demo text, line 1\r\nNew demo text, line 2");
将鼠标移动到一个元素并单击它:
browser.FullEmulation_MouseClickToElement(By.Id("checkbox3"));
暂停:
browser.Sleep(500);
获取url和页面内容:
MessageBox.Show("Page url: " + browser.GetPageUrl() + "\r\n\r\nPage content:\r\n" + browser.GetPageContent().Replace("\r\n", "").Replace("\t", ""));
检查是否缺少元素:
var elmAbsentTest = browser.ElementAbsent(By.Id("elmAbsent"), 1);
var elmAbsentTest2 = !browser.ElementAbsent(By.Id("elmInvis"), 1);
检查元素是否存在或其不可见性:
var elmAbsentInvisTest = browser.ElementAbsentOrInvisible(By.Id("elmAbsent"), 1);
var elmAbsentInvisTest2 = browser.ElementAbsentOrInvisible(By.Id("elmInvis"), 1);
var elmAbsentInvisTest3 = !browser.ElementAbsentOrInvisible(By.Id("elmVis"), 1);
检查元素是否存在:
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);
检查元素的存在及其可见性:
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);
检查元素的存在和随后的缺失(出现-消失):
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);
检查元素是否存在及其可见性,然后检查元素是否存在或其不可见性(出现-消失):
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);
检查几个元素之一的存在:
var elmExistsAnyFromArray = browser.ElementExistsAnyFromArray(new By[] { By.Id("input0"), By.Id("input1") }, 1);
元素存在/可见性测试结果:
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
));
其他方法
获取临时验证码文件名,用于下载和后续识别:
GetTempFileName("png", "captcha")
代理禁止 - 将当前代理移动到禁止列表并记录:
ProxyBanIp();
长期禁止代理 - 将当前代理移至长期禁止列表并登录:
ProxyLongbanIp();
死代理 - 将当前代理移动到死代理列表并记录:
ProxyDeadIp();
实时代理 - 记录当前代理:
ProxyGoodIp();
登录正忙 - 从文件中删除登录(如果使用):
LoginBusy(profile.Login);
结果和记录
记录:
result.Log("Debugging Data");
脚本的结果(随机:成功/错误):
result.Success = GeneratorSt.RandBool();
成功数据:
result.Data = "Success, Thread #" + Thread.CurrentThread.Name;
错误文本:
result.Error = "Error #" + GeneratorSt.Rand(1, 3);