<p>硒有两种方法</p>
<p><code>find_element</code>和<code>find_elements</code></p>
<p><strong>查找元素:</strong>-查找元素将返回单个web元素,其中</p>
<p><strong>查找元素:</strong>-将返回web元素列表</p>
<p>所以与其写这个</p>
<pre><code>browser.find_element_by_xpath("//*[contains(text(), "a list's word")]")
</code></pre>
<p>n次</p>
<p>你可以简单地做</p>
<pre><code>browser.find_elements_by_xpath("//*[contains(text(), "a list's word")]")
</code></pre>
<p><strong>注意:</strong>xpath <code>//*[contains(text(), "a list's word")]</code>应该在UI中表示多个web元素,否则,如果恰好是单个web元素,则最终将使用单个web元素</p>
<p>现在我看到你正在使用Explict等等,所以在这种情况下</p>
<p>您有很多选择,例如:</p>
<pre><code>presence_of_all_elements_located
</code></pre>
<p>或</p>
<pre><code>visibility_of
</code></pre>
<p>它们都将返回一个web元素列表,因此当您执行以下操作时:</p>
<pre><code>list_of_ele = wait.until(EC.presence_of_all_elements_located((By.XPATH, 'some xpath')))
</code></pre>
<p>现在迭代它,或者做Python允许您使用此列表执行的任何操作</p>
<p>请在此处阅读更多信息:</p>
<p><a href="https://selenium-python.readthedocs.io/waits.html" rel="nofollow noreferrer">Selenium - official docs</a></p>
<p><strong>更新1:</strong></p>
<pre><code>list = ['apple', 'police', 'etc', 'something else']
counter = 0
for search in list:
driver.find_element_by_xpath("//html/body/"+ list[counter])
counter = counter +1
</code></pre>