我的网站上有一些像这样的手风琴元素:
java CircleApp 123.456
如何在所有部分中使用selenium web驱动程序单击并保存手风琴各部分下方的链接?我试着:
<div class="col-md-12">
<a data-toggle="collapse" data-parent="#accordion1" title="Click to expand pet name" href="#petName1">
<span class="list-unstyled" style="text-decoration: none;"></span> Dog
</a>
<ul id="petName1" class="collapse">
<li>
<a href="/scripts/cder/daf/index.cfm?event=overview.process&ApplNo=200465" title="Click to view Dog | PET SHOP">
Dog</a> | PET SHOP
</a>
</li>
<li>
<a href="/scripts/cder/daf/index.cfm?event=overview.process&ApplNo=203874" title="Click to view Dog | PET SHOP">
Dog</a> | PET SHOP
</a>
</li>
</ul>
</div>
</td>
</tr>
<tr>
<td>
<div class="col-md-12">
<a data-toggle="collapse" data-parent="#accordion1" title="Click to expand pet name" href="#petName2">
<span class="list-unstyled" style="text-decoration: none;"></span> Cat
</a>
<ul id="petName2" class="collapse">
<li>
<a href="/scripts/cder/daf/index.cfm?event=overview.process&ApplNo=076477" title="Click to view Cat">
Cat
</a>
</li>
<li>
<a href="/scripts/cder/daf/index.cfm?event=overview.process&ApplNo=077575" title="Click to view Cat">
Cat
</a>
</li>
<li>
<a href="/scripts/cder/daf/index.cfm?event=overview.process&ApplNo=078773" title="Click to view Cat">
Cat</a>
</a>
</li>
<li>
<a href="/scripts/cder/daf/index.cfm?event=overview.process&ApplNo=090548" title="Click to view Cat">
Cat</a>
</a>
</li>
<li>
<a href="/scripts/cder/daf/index.cfm?event=overview.process&ApplNo=091226" title="Click to view Cat">
Cat</a>
</a>
</li>
<li>
<a href="/scripts/cder/daf/index.cfm?event=overview.process&ApplNo=091624" title="Click to view Cat">
Cat</a>
</a>
</li>
<li>
<a href="/scripts/cder/daf/index.cfm?event=overview.process&ApplNo=091650" title="Click to view Cat">
Cat</a>
</a>
</li>
<li>
<a href="/scripts/cder/daf/index.cfm?event=overview.process&ApplNo=202357" title="Click to view Cat">
Cat</a>
</a>
</li>
<li>
<a href="/scripts/cder/daf/index.cfm?event=overview.process&ApplNo=204846" title="Click to view Cat">
Cat</a>
</a>
</li>
<li>
<a href="/scripts/cder/daf/index.cfm?event=overview.process&ApplNo=205300" title="Click to view Cat">
Cat</a>
</a>
</li>
<li>
<a href="/scripts/cder/daf/index.cfm?event=overview.process&ApplNo=205519" title="Click to view Cat">
Cat</a>
</a>
</li>
</ul>
</div>
</td>
</tr>
<tr>
<td>
<div class="col-md-12">
<a data-toggle="collapse" data-parent="#accordion1" title="Click to expand pet name" href="#petName3">
<span class="list-unstyled" style="text-decoration: none;"></span> Gold Fish
</a>
<ul id="petName3" class="collapse">
<li>
<a href="/scripts/cder/daf/index.cfm?event=overview.process&ApplNo=021540" title="Click to view Gold Fish">
Gold Fish </a>
</a>
</li>
</ul>
</div>
</td>
</tr>
<tr>
<td>
<div class="col-md-12">
<a data-toggle="collapse" data-parent="#accordion1" title="Click to expand pet name" href="#petName4">
<span class="list-unstyled" style="text-decoration: none;"></span> Horse
</a>
<ul id="petName4" class="collapse">
<li>
<a href="/scripts/cder/daf/index.cfm?event=overview.process&ApplNo=020702" title="Click to view Horse">
Horse </a>
</a>
</li>
</ul>
</div>
</td>
</tr>
<tr>
<td>
<div class="col-md-12">
<a data-toggle="collapse" data-parent="#accordion1" title="Click to expand pet name" href="#petName5">
<span class="list-unstyled" style="text-decoration: none;"></span> Ferret
</a>
<ul id="petName5" class="collapse">
<li>
<a href="/scripts/cder/daf/index.cfm?event=overview.process&ApplNo=200153" title="Click to view Ferret">
Ferret </a>
</a>
</li>
</ul>
</div>
</td>
</tr>
</tbody>
然而,它没有奏效,因为它没有做任何事情(它只是停了下来)。知道如何获得所有链接并打开所有手风琴吗?。
答案 0 :(得分:0)
以下是不确定python的java代码,但你可以尝试相同的逻辑
List<WebElement> accordions = driver.findElements(By.xpath("\\a[@data-parent='#accordion1']");
这将获得列表中的所有手风琴。现在迭代列表并单击每个手风琴。
要保存每个手风琴下的链接,您可以使用上一个列表中的webelement。