<p>要单击第一个文本为Action One的ref,您可以使用以下任一选项(<em>Python Language Binding Art</em>):</p>
<ul>
<li><p><code>linkText</code>:</p>
<pre><code>driver.find_element_by_link_text("Action One").click()
</code></pre></li>
<li><p><code>cssSelector</code>:</p>
<pre><code>driver.find_element_by_css_selector("a[href*='action_one.htm']").click()
</code></pre></li>
<li><p><code>xpath</code>:</p>
<pre><code>driver.find_element_by_xpath("//a[contains(@href,'action_one.htm') and contains(.,'Action One')]").click()
</code></pre></li>
</ul>
<hr/>
<h2>更新</h2>
<p>由于您无法通过<code>LINK_TEXT</code>、<code>CSS</code>、<code>XPATH</code>找到元素,甚至在<code>time.sleep()</code>之后,都可以很好地确认元素位于由<strong><code><frame></code></strong>标记表示的<strong>框架内。</p>
<p>现在,当您能够通过“Inspect”</em>看到它们时,在<em>HTML DOM</em>中找到元素,并向上遍历<em>HTML</em>。在某个时刻,您会发现一个<code><frame></code>标记。首先获取标签的属性,然后将<em>切换到预期的<em>帧</em>,然后尝试使用我的答案中提供的<em>定位策略</em>。在这里您可以找到关于<a href="https://stackoverflow.com/questions/47770144/how-can-i-select-a-html-element-no-matter-what-frame-it-is-in-in-selenium/47771879#47771879"><strong>How can I select a html element no matter what frame it is in in selenium?</strong></a>的详细讨论</p>