Slenium_java_4 Try demo on 12306.cn (2)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.