I was too optimistic. It's take several days working on the demo. The intresting thing is if I finished the demo, I understand how to people make a Rob train seat program. JS part still isn't work, try-to-figer it out. Also, make is I should make a program to Rob Spring Festivel tickets.
Sample for Change the window in Webdriver, but it's not the good the. I should try to find framename and Windowname in JS
Set<string> handles = Wd.getwindowhandles ();
Handles.remove (Wd.getwindowhandle ());//Remove the current handle
Wd.switchto (). Window (Handles.iterator (). Next ());
The method to change window and frame is below
Webdriver.switchTo.window ("Windowname");
Webdriver.switchTo.frame ("FrameName");
import Java.util.set;import org.openqa.selenium.*; import Org.openqa.selenium.firefox.firefoxdriver;import org.openqa.selenium.interactions.HasInputDevices; Public classtest12306 { Public Static voidMain (string[] args) throws interruptedexception{//Public static void Test () throws interruptedexception{Webdriver WD =NewFirefoxdriver (); //Webdriver WD; //wd= new Firefoxdriver ();Wd.Get("http://www.12306.cn/"); //wd.get ("www.12306.cn");Thread.Sleep ( the); Wd.findelement (By.cssselector ("img[alt=\ "Buy tickets"]") . Click (); Thread.Sleep ( +); //Change to the webpage frameSet<string> handles =Wd.getwindowhandles (); Handles.remove (Wd.getwindowhandle ());//Remove the current handlewd.switchto (). Window (Handles.iterator (). Next ()); Wd.findelement (By.id ("Login_user") . Click (); Thread.Sleep ( the); Wd.findelement (By.id ("username"). SendKeys ("****@**.com"); Wd.findelement (By.id ("Password"). SendKeys ("*****"); Thread.Sleep (10000); Wd.findelement (By.id ("loginsub") . Click (); //enter the from station and to stationWd.findelement (By.id ("Fromstationtext") . Clear (); Wd.findelement (By.id ("Fromstationtext"). SendKeys ("Shanghai"); ((hasinputdevices) wd). Getkeyboard (). SendKeys (Keys.return); Wd.findelement (By.id ("Tostationtext") . Clear (); Wd.findelement (By.id ("Tostationtext"). SendKeys ("Hangzhou"); ((hasinputdevices) wd). Getkeyboard (). SendKeys (Keys.return); //enter the data from keyboard using JSString str="document.getElementById (\ "Startdatepicker\"). Readonly=false"; //String str= "document.getElementById (\" Startdatepicker\ "). Readonly=false";String strdate="document.getElementById (\ "Startdatepicker\"). Value\ "2014-01-08\""; ((Javascriptexecutor) wd). Executescript (str); ((Javascriptexecutor) wd). Executescript (strdate); Wd.findelement (By.id ("A_search_ticket") . Click (); Wd.quit (); }}
Slenium_java_4 Try demo on 12306.cn (2)