我想按位置进一步筛选搜索结果。我只想要“美国”的结果,所以要单击“美国”,其顺序根据关键字的不同而变化。
以下代码不起作用。没有错误消息,但什么也没有发生。谢谢大家!
browser.implicitly_wait(30)
element = browser.find_element_by_xpath("//span[contains(text(),'United
States')]")
browser.execute_script("arguments[0].click();", element)
如果成功,则“美国”也应出现在狭义By列表中:
The HTML source is as follows:
<ul class="supplemental filters " aria-labelledby="podfiltersbuttonlocation" data-id="location">
<li class="preferred">
<h3 class="closable">
<span>
Select location by publications to display at the top of this list. <a
href="#" data-action="editpreferred">Edit Settings</a>
</span>
<button data-action="dismisspreferred" type="button" class="icon la-
CloseRemove">
<span role="tooltip" class="tooltip">Dismiss this message</span>
</button>
</h3>
</li><li>
<input type="checkbox" data-id="pf0" data-value="International" id="_sp79k_pf0"
data-filtertype="location">
<label for="_sp79k_pf0" aria-label="">
<span>International</span>
<span class="count">83,428</span>
</label>
</li>
<li>
<input type="checkbox" data-id="pf1" data-value="United States" id="_sp79k_pf1"
data-filtertype="location">
<label for="_sp79k_pf1" aria-label="">
<span>United States</span>
<span class="count">31,153</span>
</label>
</li>
<li>
<input type="checkbox" data-id="pf2" data-value="Non-jurisdictional" id="_sp79k_pf2"
data-filtertype="location">
<label for="_sp79k_pf2" aria-label="">
<span>Non-jurisdictional</span>
<span class="count">10,936</span>
</label>
</li>
<li>
<input type="checkbox" data-id="pf3" data-value="California" id="_sp79k_pf3" data-
filtertype="location">
<label for="_sp79k_pf3" aria-label="">
<span>California</span>
<span class="count">6,785</span>
</label>
</li>
<li>
<input type="checkbox" data-id="pf4" data-value="Georgia" id="_sp79k_pf4" data-
filtertype="location">
<label for="_sp79k_pf4" aria-label="">
<span>Georgia</span>
<span class="count">2,814</span>
</label>
</li>
<li class="more">
<button data-action="moreless" class="icon la-ShowMore" type="button">
More
</button>
</li>
<li class="sel-multi">
<button type="button" data-action="selmulti" rel="modal" href="/modals/select-
Filters.shtml">Select multiple</button>
</li>
</ul>
点击
checkbox
诱导WebDriverWait
()和element_to_be_clickable
()和后面的Xpath
您需要导入以下库
相关问题 更多 >
编程相关推荐