代码如下
package selenium_Test;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.*;
import org.openqa.selenium.WebDriver.*;
public class Collection {
public static void main (String args[]) throws Exception
{
System.setProperty("webdriver.firefox.bin", "E:\\software\\firefox\\firefox.exe");
WebDriver driver=new FirefoxDriver();
driver.navigate().to("http://www.jd.com");
System.out.println("检查是否进入京东首页:"+driver.getCurrentUrl().equals("http://www.jd.com/"));
driver.findElement(By.id("key")).sendKeys("2269");
driver.findElement(By.className("button")).click();
System.out.println("检查搜索页面是否跳转正确:"+driver.getCurrentUrl().equals("http://search.jd.com/Search?keyword=2269&enc=utf-8"));
driver.findElement(By.partialLinkText("AOC I2269VW 21.5英寸LED背光超窄边框IPS广视角液晶显示器(银色)")).click();
System.out.println("检查是否进入之前选择的商品页面:"+driver.getCurrentUrl().equals("http://item.jd.com/845638.html"));
// System.out.println("检查商品价格是否准确:"+driver.findElement(By.id("jd-price]")).getText().contains("¥869.00"));
driver.quit();
}
}
执行结果:
检查是否进入京东首页:true 检查搜索页面是否跳转正确:true 检查是否进入之前选择的商品页面:false
问题描述请看博客摘要
原文:http://my.oschina.net/u/2299197/blog/363303