【发布时间】:2021-12-30 13:51:54
【问题描述】:
下面是如何设置页面的 sn-p。
<class id="class1">
<ul>
<li>
<strong>section 1</strong>
<a href="link.com/home1">some link 1</a>
<li>
<strong>section 2</strong>
<a href="link.com/home">some link 2</a>
<class id="class1">
<ul>
<li>
<strong>section 3</strong>
<a href="link.com/home/abc">some link 3</a>
<li>
<strong>section 4</strong>
<a href="link.com/home/def">some link 4</a>
如何在第 2 部分找到 link.com/home?
我认为这会起作用:
.class1:nth-of-type(1) li:nth-child(2) [href*="/home"]
但事实并非如此。它也在第 4 节中找到了链接。我必须使用 *= 因为在不同的环境中 url 前缀会发生变化。
【问题讨论】:
标签: python selenium selenium-webdriver css-selectors webdriver