如何使用Selenium WebDriver获取整数值

时间:2013-09-26 10:10:28

标签: webdriver

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);

我必须打印黄金价值....任何人都可以帮助我

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分: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());
}