/** * Type characters. * Assume that you have Internet Explorer and Selenium Server is running on your * computer on default port 4444. Otherwise, change accordingly in the constructor. * You need to change the encoding of your editor to support the Chinese characters below. * @Author: Xuan Ngo */ import com.thoughtworks.selenium.DefaultSelenium; public class WritingExample { private DefaultSelenium m_oBrowser = null; public static void main(String[] args) { Writing oWriting = new Writing(); // Type characters. oWriting.runExamples(); } // Constructor public Writing() { this.m_oBrowser = new DefaultSelenium("localhost", 4444, "*iexplore", "http://openwritings.net/"); // *iexplore, *firefox this.m_oBrowser.start(); // Start Selenium. this.m_oBrowser.open("http://openwritings.net/sites/default/files/type.html"); // Open the webpage. } // Type characters. public void runExamples() { // Type characters using different locators and field types. this.m_oBrowser.type("xpath=//*[@name='first-name']", "Xuan"); // XPATH locator. this.m_oBrowser.type("css=input[name=last-name]", "Ngo"); // CSS locator. this.m_oBrowser.type("dom=document.getElementsByName('my-password').item(0)", "my password"); // DOM locator. this.m_oBrowser.type("xpath=//*[@name='chinese-chars']", "中文");// Type Chinese characters. You need to change the encoding of your editor. // Simulates keystroke events on the specified element, as though you typed the value key-by-key. // "auto complete" = a,u,t,o, ,c,o,m,p,l,e,t,e this.m_oBrowser.typeKeys("css=input[name=key-press]", "auto complete"); // CSS locator. //this.m_oBrowser.stop(); // Close Selenium. } }