擅长:python、mysql、java
<p>所需的元素是<a href="https://angular.io/" rel="nofollow noreferrer">Angular</a>元素,因此要在元素上定位和<code>click()</code>,您需要为<code>element_to_be_clickable()</code>诱导<em>WebDriverWait</em>,并且可以使用以下任一<a href="https://stackoverflow.com/questions/48369043/official-locator-strategies-for-the-webdriver/48376890#48376890">Locator Strategies</a>:</p>
<ul>
<li><p>使用<code>CSS_SELECTOR</code>:</p>
<pre><code>WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "li>a[href$='customReports'][translate*='CustomReports']"))).click()
</code></pre></li>
<li><p>使用<code>XPATH</code>:</p>
<pre><code>WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//li/a[contains(@href,'customReports') and contains(@translate, 'CustomReports')]"))).click()
</code></pre></li>
<li><p><strong>注意</strong>:您必须添加以下导入:</p>
<pre><code>from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
</code></pre></li>
</ul>