The following code shows how Helium can be used to automatically post a tweet on Twitter:

import static com.heliumhq.API.*;
import java.util.Scanner;

public class TwitterExample {
    private static String message = 
        "Trying web automation with #helium from @BugFreeSoftware. heliumhq.com";

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Twitter username:");
        String email = sc.nextLine();
        System.out.println("Twitter password:");
        String password = sc.nextLine();
        sc.close();
        startFirefox("twitter.com");
        write(email, into("Phone, email or username"));
        write(password, into("Password"));
        click("Log in");
        click("Tweet");
        write(message);
        click("Tweet");
        killBrowser();
    }
}
from helium.api import *

email = raw_input("Twitter username: ")
password = raw_input("Twitter password: ")
message = "Trying web automation with #helium from @BugFreeSoftware. heliumhq.com"

start_chrome('twitter.com')
write(email, into="Phone, email or username")
write(password, into="Password")
click("Log in")
click("Tweet")
write(message)
click("Tweet")
kill_browser()

The script first prompts for your Twitter username and password. Then, it composes a new tweet and posts it to your followers.

To run the script, follow the steps on our Getting Started page to set up Helium. Then execute the run.bat/run.sh shell script in the examples/Post on Twitter subdirectory of your Helium installation.