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.
question from:
https://stackoverflow.com/questions/65890247/how-can-i-extract-a-list-of-ids-from-a-webpage 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…