testng中怎么取不到属性值。。。

上一篇 / 下一篇  2012-04-27 15:55:29 / 个人分类:TestNG/Ant/Eclipse/Java

package ENSG;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
//import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.testng.annotations.*;
import static org.testng.Assert.*;
import com.thoughtworks.selenium.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
@Test
public class headerBar {
public void msnlogo() {
 WebDriver driver = new FirefoxDriver();
 //WebDriver driver = new HtmlUnitDriver();  
        driver.get("http://xin.msn.com/default.aspx");
        WebElement headlogo=driver.findElement(By.id("headlogo"));
        String width = headlogo.getAttribute("src");
        System.out.println(width);
 }   
}

TAG:

MillionRoses 引用 删除 dian106106   /   2012-04-27 17:58:50
driver.findElement(By.xpath("//img[@alt='msn']")).getAttribute("src");

ok了
MillionRoses 引用 删除 dian106106   /   2012-04-27 15:57:21
用selenium1 就是好的。
package ENSG;

import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;
//import static org.junit.Assert.*;

public class lianxi3 extends SeleneseTestCase {
public void setUp() throws Exception {
  setUp("http://xin.msn.com/default.aspx", "*chrome");
}
public void testTest123() throws Exception {
  selenium.open("/");
  String var=selenium.getAttribute("alt=msn@src");
  String var1=selenium.getAttribute("alt=msn@width");
  System.out.println(var);
  System.out.println(var1);
  }
}
 

评分:0

我来说两句

日历

« 2024-05-10  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 74550
  • 日志数: 80
  • 建立时间: 2012-04-12
  • 更新时间: 2013-05-21

RSS订阅

Open Toolbar