Helpful code snippets

smol84

Client
Регистрация
06.01.2012
Сообщения
30
Благодарностей
2
Баллы
0
Thought I would start a thread that contains some quick snippets of code that may benefit others .

Most of the stuff I have come across isn't in the help files, or forums, or sometimes anywhere so I hope this helps someone
 

smol84

Client
Регистрация
06.01.2012
Сообщения
30
Благодарностей
2
Баллы
0
how to pull dom, html or text
Код:
tb.DOmText //get page dom
tb.PageText;  //get page text
tb.GetSourceText; //get source text
Method() to write to file - call this with WriteFile.WriteToFile(string goes here)
Код:
using System;
using System.IO;
using Zennolab.CommandCenter;

namespace foo
{
	internal class WriteFile
	{
		public static void WriteToFile(string line)
		{
			StreamWriter file =
				new StreamWriter(
				new FileStream(@"C:\\file.txt", FileMode.Append, FileAccess.Write));
			file.WriteLine(line);
			
			file.Close();
		}
	}
}


Sometimes when working with ajax drop down boxes the selectitems wont work if the drop down value loads the next drop down for you to select - get around this with:
Код:
// Set dropdown
he = instance.GetTabByAddress("page").GetDocumentByAddress("0").FindElementByTag("form", 1).FindChildByName("dropdown");
if (he.IsVoid) {
    ErrorLog.WriteError("unable to find field: "+ "dropdown");
    return -1;
}

//Set/Get/Set
he.SetAttribute("selecteditems", input);
if (!he.IsVoid) attribute = he.GetAttribute("value");
he.SetValue(attribute, true);
System.Threading.Thread.Sleep(1000);

Sometimes you may want to find and click an object on a site but you can't find what you need in probranch builder, but you can see that there are attributes in the elements of the field. In this example the element i use is OuterHTML
Код:
he = instance.GetTabByAddress("page").GetDocumentByAddress("0").FindElementByTag("form", 0).FindChildByAttribute("input:radio", "outerhtml", "myTexttoSEARCH", "text", 0);
I hope this helps someone.

Please post your code snippets here too and help your zenno friends
 
  • Спасибо
Реакции: mta и kvdd

prosperer888

Client
Регистрация
15.09.2011
Сообщения
157
Благодарностей
4
Баллы
18
lol i didn't understand this :( where should i put the code =)
 

smol84

Client
Регистрация
06.01.2012
Сообщения
30
Благодарностей
2
Баллы
0

kvdd

Client
Регистрация
05.05.2011
Сообщения
37
Благодарностей
0
Баллы
6
Aren't you not always in the situation that you need to register a new account with:
  • First name
  • Last name
  • Username
  • birth dates
  • Password

I have a default script for it:
Код:
Random random = new Random();
int year = random.Next(1954, 1991);
int month = random.Next(1,12);
int day = random.Next(1,28);
			
string first = instance.RiseMacros("File.GetString", new [] { "\\Resources\\male.txt", "random", "false" });
string last = instance.RiseMacros("File.GetString", new [] { "\\Resources\\lastnames.txt", "random", "false" });
string username = first + last + year;
username = username.ToLower();
			
string password = instance.RiseMacros("Random.Text", new [] { "8", "cd" });
.txt files are pointing to my own created names and lastnames.
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)