Selenium_Java实例代码(2)

package cn.selenium2.test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Xpath_Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
   WebDriver driver=new FirefoxDriver();
   driver.get("http://www.baidu.com"); 
   //打开登录框
  //WebElement  elem1=driver.findElement(By.xpath("//a[@id='lb']"));
   //WebElement  elem1=driver.findElement(By.xpath("//a[text()='登录']"));
  // WebElement  elem1=driver.findElement(By.xpath("//a[@name='tj_login']"));
  // WebElement  elem1=driver.findElement(By.xpath("//div[@id='u']//a[2]"));
   WebElement  elem1=driver.findElement(By.xpath("//div[@id='content']/div/a[2]"));
   elem1.click();
   System.out.println(elem1.getText());
   //关闭登录框
   WebElement elem2=driver.findElement(By.xpath("//*[@id='TANGRAM__PSP_4__closeBtn']"));
   elem2.click();
   driver.quit();
}


}

你可能感兴趣的:(Selenium_Java实例代码(2))