get attributeby不起作用

时间:2014-10-29 09:12:31

标签: java selenium webdriver

        String a=driver.findElement(By.id(locator))).getAttribute("value");

        System.out.println("the value is "+ a);

        Log.info(" Required object is present in the applicaiton"+ object);

        <p locale="" isnumeric="false" basetype="String" class="outputText twControl twOutputText" id="InputText12">**MANTPLAP29102014100955627**</p>

我需要从上面的HTML代码中获取MANTPLAP29102014100955627值。 请帮忙..

1 个答案:

答案 0 :(得分:0)

使用

driver.findElement(By.id(locator))).getText();

修改

getAttribute和getText方法之间存在差异

考虑像这样的html标签

<input type = "text" id = "id" name = "bird">Peagon</input>

现在使用     driver.findElement(By.id("id"))).getAttribute("name")会将值返回为bird(这是属性&#39; name&#39;的值) 并使用

driver.findElement(By.id(locator))).getText();将返回Peagon的值(开始和结束<input>标记之间的文字)