0

Hi i have this html code:

<div id="idvalue" value="56"></div>

And i want to get the value '56'. How can i do that? I tried this but it returns null.

System.out.println(driver.findElement(By.id("idvalue")).getAttribute("value"));

I am using Selenium 2 Please help..

7
  • Try System.out.println(driver.findElement(By.id("idvalue")).getText()); Commented Apr 16, 2013 at 15:23
  • That returns what is inside div tag. If i have: <div id="idvalue" value="56">test</div> it returns "test" Commented Apr 16, 2013 at 15:25
  • Are you sure you have only one element with id="idvalue" Commented Apr 16, 2013 at 15:34
  • Yes i am sure of that. Commented Apr 16, 2013 at 15:37
  • @LuisCarlos Try System.out.println(driver.findElement(By.id("idvalue")).getCssValue("value")); Commented Apr 16, 2013 at 16:03

2 Answers 2

3

value is no valid attribute for the div element. You shouldn't be surprised that this does not work...

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, but afaik, they need to start with "data-". And even then, I don't know if selenium2 supports that...
1

did you tried this way

JavascriptExecutor js = (JavascriptExecutor)driver;
Object val=js.executeScript("return document.getElementById('idvalue').getAttribute('value');");

System.out.println("Value attr value: " + val);

output: Value attr value: 56

1 Comment

Thanks for reply, but i found that this number i have to retrive i finded in another div like this way: <div id="idvalue">56</div> And that is simple.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.