0
WebDriver driver=new FirefoxDriver();
    driver.get("http://www.grtjewels.com");
    driver.findElement(By.id("CollapsiblePanel1txt")).click();
    e=( driver.findElement(By.xpath(".//*[@id='CollapsiblePanel1']/div/p[5]")).getAttribute("value"));
    System.out.println("The output is " +e);

我必须打印黄金价值....谁能帮帮我

4

2 回答 2

0

看起来像一个同步问题 请参阅下面的等待直到元素可见的使用

 public static void main(String[] args) {
    WebDriver driver=new FirefoxDriver();
    driver.get("http://www.grtjewels.com");

    driver.findElement(By.id("CollapsiblePanel1txt")).click();
    WebElement e = driver.findElement(By.xpath(".//*[@id='CollapsiblePanel1']/div/p[5]"));

    //Waiting for the element to be visible
    Wait wait = new WebDriverWait(driver, 10);
    wait.until(ExpectedConditions.visibilityOf(e));

    System.out.println("The output is " +e.getText());
}
于 2013-09-29T06:36:32.793 回答
0

您是否尝试仅打印元素的选定值?您是否尝试过 driver.findElement(By.xpath(".//*[@id='CollapsiblePanel1']/div/p[5]")).getText()

于 2013-09-26T13:34:47.983 回答