求助cssSelector定位的contains用法
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")).click();
driver.findElement(By.cssSelector("img")).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().toArray(handles);
for (int i = 0; i < handles.length; i++)
{
System.out.println("switch:"+i+":"+handles);
}
driver.switchTo().window(handles);
//WebDriver childWindow = driver.switchTo().window(handles);
//((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();
}
}
我没听说过css里面带contains的,xpath才可以带contains cssSelector的值取得不对吧
页:
[1]