擅长:python、mysql、java
<p>使用<a href="https://selenium-python.readthedocs.org/api.html#module-selenium.webdriver.common.action_chains" rel="noreferrer">Action Chains</a>:</p>
<pre><code>from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
N = 5 # number of times you want to press TAB
actions = ActionChains(browser)
for _ in range(N):
actions = actions.send_keys(Keys.TAB)
actions.perform()
</code></pre>
<p>或者,由于这是Python,您甚至可以:</p>
<pre><code>actions = ActionChains(browser)
actions.send_keys(Keys.TAB * N)
actions.perform()
</code></pre>