51Testing软件测试论坛
标题:
求助cssSelector定位的contains用法
[打印本页]
作者:
wsryyffs
时间:
2014-3-14 12:55
标题:
求助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[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();
}
}
复制代码
作者:
六月天
时间:
2014-3-14 17:14
我没听说过css里面带contains的,xpath才可以带contains
作者:
joykao
时间:
2014-3-17 09:59
cssSelector的值取得不对吧
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2