Sep 13, 2015 11:59 AM
Requirements:
- Basic coding knowledge
- Visual Studio (Im using Visual Studio 2013 you can download it from official website. Dont install cracked ones etc, free one works well)
Ill show you here how I do different tasks in geckofx embedded browser. Have in mind that I will update this thread with more things like how to remove ads so we wont need to load them, how to wait for element to appear and so on..
How to click html elements - button, image, checkbox, radiobox or any other clickable html object which we need to click.
ClickByText
With this method we can find html element by its tag and text content. For example when inspecting like button in facebook we get something like this

I believe many of you who tried iMacros ran into trouble when tried to click this html element and its because id and other attributes chages all the time. You would need some parsing if you want to get right attribute and click it.
We dont need attribute because that button have its text content which is 'Like'. So we just use this function :
ClickByAttribute
What if there is no text content or it always changes? We can easly locate element by its attribute.
Lets click 'Rules' link in our a2s forum. When we inspect element we get this
So our TagName is "a" and we have attributeType which is "href" and its text - "//a2s.in/announcements/4-rules-regulations.html".
How to Input Text
With this method we can locate inputbox and fill in information. For example lets input message in our subbox input box
When we inspect element we get this
so to be able to fill text into this inputbox we need TagName, AttributeText and ofcourse your text which you want to input
Example
Since we have methods we can use them in automating something. Lets try to login into our forum. We will use both click element and input methods.
Here is base project where you can try to code. I already included geckofx browser, shown methods and login into warofclicks example. You can try to continue automating it.. https://www.dropbox.com/s/bbvikdim7e4w3hh/MyFirstBot.rar?dl=1
---------------------------------------------------------
If you never coded before then you cant just jump in into more advanced things. You have to read basic things about C# and know how everything works. You dont need to memorize it just know where needed info is located.
If you get too many errors then dont worry about it, fix them one by one.
---------------------------------------------------------
To Do:
- List with compilation of most useful ebooks to learn C#
- Tutorial how to include newest geckofx files into your C# project
- Geckofx bot examples
- Http request tutorial
- How to obfuscate your code and decompile other .net applications
- Much more
---------------------------------------------------------
Side note: Please ask all questions and even stupid ones about this subject. I'm bad teacher and cant know what you dont understand so Ill try my best to explain everything if you ask.
Important: Dont post offtopic messages here. Only write/ask about coding.
- Basic coding knowledge
- Visual Studio (Im using Visual Studio 2013 you can download it from official website. Dont install cracked ones etc, free one works well)
Ill show you here how I do different tasks in geckofx embedded browser. Have in mind that I will update this thread with more things like how to remove ads so we wont need to load them, how to wait for element to appear and so on..
How to click html elements - button, image, checkbox, radiobox or any other clickable html object which we need to click.
ClickByText
public async TaskClickByText(GeckoWebBrowser wBrowser, string TagName, string TextContent, int TimeOut = 15)
{
bool Found = false;
int Failed = 0;
for (int i = 1; i <= TimeOut; i++) //We will try to search element for 15 seconds
{
try
{
foreach (GeckoHtmlElement geckoHtmlElement in wBrowser.Document.GetElementsByTagName(TagName))
{
if (!geckoHtmlElement.TextContent.Contains(TextContent)) { Failed = Failed + 1; }
if (Failed >= 1) { Failed = 0; continue; }
else if (Failed < 1) { geckoHtmlElement.Click(); Found = true; break; }
}
if (Found == true) { return true; }
await Task.Delay(1000);
}
catch (Exception e) { MessageBox.Show("Error clicking element 1 " + e); return false; }
}
return false;
}
With this method we can find html element by its tag and text content. For example when inspecting like button in facebook we get something like this

I believe many of you who tried iMacros ran into trouble when tried to click this html element and its because id and other attributes chages all the time. You would need some parsing if you want to get right attribute and click it.
We dont need attribute because that button have its text content which is 'Like'. So we just use this function :
await ClickByText(wBrowser, "button", "Like");
ClickByAttribute
What if there is no text content or it always changes? We can easly locate element by its attribute.
public async TaskClickByAttribute(GeckoWebBrowser wBrowser, string TagName, string attributeType, string attributeText, int TimeOut = 15)
{
bool Found = false;
int Failed = 0;
for (int i = 1; i <= TimeOut; i++)
{
try
{
foreach (GeckoHtmlElement geckoHtmlElement in wBrowser.Document.GetElementsByTagName(TagName))
{
if (!(geckoHtmlElement.GetAttribute(attributeType) == attributeText)) { Failed = Failed + 1; }
if (Failed >= 1) { Failed = 0; continue; }
else if (Failed < 1) { geckoHtmlElement.Click(); Found = true; break; }
}
if (Found == true) { return true; }
await Task.Delay(1000);
}
catch (Exception e) { MessageBox.Show("Error clicking element 2" + e); return false; }
}
return false;
}
Lets click 'Rules' link in our a2s forum. When we inspect element we get this

So our TagName is "a" and we have attributeType which is "href" and its text - "//a2s.in/announcements/4-rules-regulations.html".
await ClickByAttribute(wBrowser, "a", "href", "//a2s.in/announcements/4-rules-regulations.html");
How to Input Text
public async TaskInputByAttribute(GeckoWebBrowser wBrowser, string TagName, string AttributeType, string AttributeText, string YourText,int TimeOut = 15)
{
bool Found = false;
int Failed = 0;
for (int i = 1; i <= TimeOut; i++)
{
try
{
foreach (GeckoInputElement geckoHtmlElement in wBrowser.Document.GetElementsByTagName(TagName))
{
if (!(geckoHtmlElement.GetAttribute(AttributeType) == AttributeText)) { Failed = Failed + 1; }
if (Failed >= 1) { Failed = 0; continue; }
else if (Failed < 1) { geckoHtmlElement.Value = YourText; Found = true; break; }
}
if (Found == true) { return true; }
await Task.Delay(1000);
}
catch (Exception e) { MessageBox.Show("Error filling info 1" + e); return false; }
}
return false;
}
With this method we can locate inputbox and fill in information. For example lets input message in our subbox input box

When we inspect element we get this
so to be able to fill text into this inputbox we need TagName, AttributeText and ofcourse your text which you want to inputawait InputByAttribute(wBrowser,"input", "class", "primary full textbox", "Hello");
Example
Since we have methods we can use them in automating something. Lets try to login into our forum. We will use both click element and input methods.
public async Task Login(GeckoWebBrowser wBrowser, string username, string password)
{
//Fill username
await InputByAttribute(wBrowser, "input", "id", "navbar_username", username);
//Fill password
await InputByAttribute(wBrowser, "input", "id", "navbar_password_hint", password);
//Click button to login
await ClickByAttribute(wBrowser, "input","type","submit");
}
Here is base project where you can try to code. I already included geckofx browser, shown methods and login into warofclicks example. You can try to continue automating it.. https://www.dropbox.com/s/bbvikdim7e4w3hh/MyFirstBot.rar?dl=1
---------------------------------------------------------
If you never coded before then you cant just jump in into more advanced things. You have to read basic things about C# and know how everything works. You dont need to memorize it just know where needed info is located.
If you get too many errors then dont worry about it, fix them one by one.
---------------------------------------------------------
To Do:
- List with compilation of most useful ebooks to learn C#
- Tutorial how to include newest geckofx files into your C# project
- Geckofx bot examples
- Http request tutorial
- How to obfuscate your code and decompile other .net applications
- Much more
---------------------------------------------------------
Side note: Please ask all questions and even stupid ones about this subject. I'm bad teacher and cant know what you dont understand so Ill try my best to explain everything if you ask.
Important: Dont post offtopic messages here. Only write/ask about coding.