ฉันจะแน่ใจได้อย่างไรว่าโค้ดซีลีเนียมของฉันจะดึงเนื้อหาที่ตรงกันทั้งหมดของ XPath ของฉัน
โปรดช่วยฉันด้วยไอเดียของคุณ
ตัวอย่างเช่น นี่คือแท็ก HTML ของฉัน:
<tr class="1" role="r1">
<td class="c1">
<a href="/thwww.google.com">
</a>
</td>
</tr>
<tr class="2" role="r2">
<td class="c2">
<a href="/thwww.youtube.com">
</a>
</td>
</tr>
<tr class="3" role="c3">
<td class="c3">
<a href="/thwww.facebook.com">
</a>
</td>
</tr>
ฉันต้องการให้โค้ดซีลีเนียมดึงลิงก์ทั้งหมดจากแท็ก href
ดังนั้น ด้านล่างนี้คือ XPath ของฉัน:
String links = driver.findElement(By.xpath("//tr[@role='cad']//td[@class='c1']//a")).getAttribute("href");
System.out.println(links);
แต่จะดึงเฉพาะเอาต์พุต href แรกเท่านั้น เช่น www.google.com
ผลลัพธ์ที่ต้องการคือ:
www.google.com
www.youtube.com
www.facebook.com
ฉันจะบรรลุสิ่งนี้ได้อย่างไร
การใช้งานอาร์เรย์ใด ๆ จะเป็นตัวเลือกที่ดีกว่า
driver.findElements()
แล้วหรือยัง? หมายเหตุ s พิเศษสำหรับองค์ประกอบพหูพจน์ - person SiKing   schedule 01.04.2017String links =((WebElement) driver.findElement(By.xpath("//tr[@role='cad']//td[@class='c1']//a"))).getAttribute("href")
มันใช้งานได้ ... ข้อเสนอแนะใด ๆ ??string
ประเภทข้อมูลไม่ตรงกันใช่ไหม - person user3624000   schedule 01.04.2017