I have this code in a web page I am trying to scrape with selenium:
<h4 class="category" id="sc_14295">...</h4>
<h4 class="category" id="sc_14292">...</h4>
<h4 class="category" id="sc_14291">...</h4>
<h4 class="category" id="sc_14299">...</h4>
I have tried to implement a method like this (which I found here on SO) to get at least one id:
String id = driver.findElement(By.xpath("//div[@class='category']")).getAttribute("id");
in this way:
String id = driver.findElement(By.xpath("//h4[@class='category']")).getAttribute("id");
It doesn't work. I assume I should be using findElements()
but that can't have getAtttribute. How can I extract a list of all id's?
Thanks.