TA的每日心情 | 开心 2015-5-5 13:21 |
---|
签到天数: 1 天 连续签到: 1 天 [LV.1]测试小兵
|
driver.findElement(By.cssSelector("span.ralign:contains('大连北')")).click();,定位失败,
driver.findElement(By.cssSelector("span.ralign")).click();定位成功
谁知道怎么回事啊- package test;
- import org.openqa.selenium.By;
- import org.openqa.selenium.JavascriptExecutor;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.firefox.FirefoxDriver;
- public class test12306 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- WebDriver driver=new FirefoxDriver();
- driver.get("http://www.12306.cn/");
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- //driver.findElement(By.cssSelector("img[alt=\"购票\"]")).click();
- driver.findElement(By.cssSelector("img[alt='购票']")).click();
- //driver.findElement(By.xpath("//img[@alt='购票']")).click();
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- String[] handles=new String[driver.getWindowHandles().size()];
- driver.getWindowHandles().toArray(handles);
-
- for (int i = 0; i < handles.length; i++)
- {
- System.out.println("switch:"+i+":"+handles[i]);
- }
- driver.switchTo().window(handles[1]);
- //WebDriver childWindow = driver.switchTo().window(handles[1]);
-
-
- //((JavascriptExecutor)driver).executeScript("document.getElementById(\"train_date\").readonly=false");
- //((JavascriptExecutor)driver).executeScript("document.getElementById(\"train_date\").value='2014-3-28 周二'");
- driver.findElement(By.id("fromStationText")).click();
- driver.findElement(By.id("fromStationText")).sendKeys("大连北");
- //driver.findElement(By.xpath(".//*[@id='citem_0']/span")).click();
- //driver.findElement(By.cssSelector("span.ralign:contains('大连北')")).click();
- driver.findElement(By.cssSelector("span.ralign")).click();
- driver.findElement(By.id("toStationText")).click();
- driver.findElement(By.id("toStationText")).sendKeys("沈阳北");
- driver.findElement(By.xpath(".//*[@id='citem_0']/span")).click();
-
- driver.findElement(By.id("query_ticket")).click();
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
-
- driver.quit();
- }
- }
复制代码 |
|