I try to write a simple web Bot in Java (WebDriver). I created two classes. One is scanning google for pages I like and returning next link page when i call getnextadress() method. The second was written to visit this page and insert text there (posttext()). Everything is working properly if i run this without Threads. But what I want to achieve is to run about three threads posting my text. And when the class finishes posting, I want it to call for next link. I can't achieve this in anyway. How to run four classes cooperating together. Here is Google class:
public class Google{
public String getnextadress() throws InterruptedException{
String adress = null;
long end = System.currentTimeMillis() + 30000; //czas po kotrym przestac ladowac strone
while (System.currentTimeMillis() < end){
if(aktualnylink==10){ //przeskoczenie do kolejnej strony googla
aktulanastrona++;
aktualnylink=0;
driver.findElement(By.linkText(Integer.toString(aktulanastrona))).click();
Thread.sleep(2000L);
gettitles();
}
String text = linkElements.get(aktualnylink).getText();
driver.findElement(By.linkText(text)).click();
Thread.sleep(2000L);
adress = driver.getCurrentUrl();
Thread.sleep(2000L);
while (!driver.getCurrentUrl().contains("google")){
driver.navigate().back();}
aktualnylink++;
Thread.sleep(2000L);
gettitles();
break;
}
return adress;
}
And now positng class:
public class Commenter{
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public void postcomment(String adress){
try{
gotopage(adress);
tekst = driver.findElement(By.id("IDCommentNewThreadText"));
tekst.sendKeys(teksts);
klikacz = driver.findElement(By.linkText("Submit Comment"));
klikacz.click();
}
catch(Exception ignored){System.out.println("Brak mozliwosci komentowania na blogu "+adress); }
}
} I hope that this bit of code is enough. Show me example how to run them properly in Main class. PS. Sorry for my poor language skill.