<p><em>类</em>属性的值,即<code>jumbo Z12Rgj4 buttonWrapper x8uow audioBtn 1H6rCK</code>是动态的,每次访问应用程序时都会不断更改。要单击文本为“保存”的元素,可以使用以下任一<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>driver.find_element_by_css_selector("[class^='jumbo']").click()
</code></pre>
</li>
<li><p>使用<code>xpath</code>:</p>
<pre><code>driver.find_element_by_xpath("//*[starts-with(@class, 'jumbo')]").click()
</code></pre>
</li>
</ul>
<p>理想情况下,要单击需要为<code>element_to_be_clickable()</code>诱导<a href="https://stackoverflow.com/questions/59130200/selenium-wait-until-element-is-present-visible-and-interactable/59130336#59130336">WebDriverWait</a>的元素,可以使用以下<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(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "[class^='jumbo']"))).click()
</code></pre>
</li>
<li><p>使用<code>XPATH</code>:</p>
<pre><code>WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[starts-with(@class, 'jumbo')]"))).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>