How to read id value of a DIV element using Selenium WebDriver?

firefox, selenium, selenium-webdriver, webdriver

Solution

You can try this :

String id=driver.findElementByXpath("//div[@class='errorblock']").getAttribute("id"));

But in this case the class of this division should be unique.

Problem

``` <div id="ctl00_ContentHolder_vs_ValidationSummary" class="errorblock"> <p><strong>The following errors were found:</strong></p> <ul><input type="hidden" Name="SummaryErrorCmsIds" Value="E024|E012|E014" /> <li>Please select a title.</li> <li>Please key in your first name.</li> <li>Please key in your last name.</li> </ul> </div> ``` here is my snippet for example. i want to get the value of ID i.e., ct100_contentHolder_vs_ValidationSummary. using selenium web driver. h

Original source