-2
我有下面的代碼,並希望在「galeria003」僅計算圖像(我也有其它畫廊在頁面上IMGS)計數一些影像使用硒
<div id="classepai" class="carrossel">
<div class="galeria003">
<div class="conjuntoimgs">
<div class="imagem_item">
<div>
<a href="https://localhost/pagina1.html"><img src="https://localhost/foto1.jpg"></a>
</div>
</div>
<div class="imagem_item">
<div>
<a href="https://localhost/pagina2.html"><img src="https://localhost/foto2.jpg"></a>
</div>
</div>
</div>
</div>
<div class="galeria004">
<div class="conjuntoimgs">
(...)
</div>
</div>
我試圖與下面的代碼,但它會返回頁面上的所有圖像。
public int galeria03() {
List<WebElement> lista03 = driver.findElements(By.tagName("img"));
int count = 0;
for(WebElement e : lista03) {
count++;
}
return count;
在Python有方法find_elements_by_class_name可能適合你。我想你可以在你的語言中找到類似的綁定(C/Java?)。然後你得到你的圖像在這裏面,無論是使用你的原代碼或類似innerHTML或文本和使用正則表達式來找到網址 –