擅长:python、mysql、java
<p>您需要将for循环中的索引转换为字符串并在xpath中使用:</p>
<pre><code>follow_loop = range(1, 11)
for x in follow_loop:
xpath = "/html/body/div[7]/div/div/div[2]/div["
xpath += str(x)
xpath += "]/div[2]/div[1]/div/button"
driver.find_element_by_xpath(xpath).click()
</code></pre>
<p>另外,通常会有一种更简洁/更好的方法来选择元素,而不是使用XPath<code>/html/body/div[7]/div/div/div[2]</code>。尝试按类或按id选择元素,例如:</p>
^{pr2}$