擅长:python、mysql、java
<p>您可以通过xpath找到它们</p>
<p>即:</p>
<pre><code><html>
<body>
<form id="loginForm">
</body>
<html>
</code></pre>
<p>你可以通过:</p>
<pre><code>login_form = driver.find_element_by_xpath("/html/body/form[1]")
</code></pre>
<p>这里的数字1表示它是第一种形式。
在您的情况下,如果您知道表格,您可以使用以下内容(只需更改数字以匹配您的数字。即,如果是第4个输入,则将值更改为4)</p>
<pre><code>driver.find_element_by_xpath("//form[1]/input[1]")
</code></pre>
<p>另一种选择是在名称、类型和其他一些属性不变的情况下,您可以使用(链接它们,使它们指向唯一的元素):</p>
<pre><code>driver.find_element_by_xpath("//input[@name='emailAddress'][@type='email']")
</code></pre>
<p>要验证xpath是否有效,请尝试web检查器中的搜索框,它接受xpath,如果它找到您的元素,那么它也可以在python中工作</p>
<p>有关更多方法,请参阅<a href="https://selenium-python.readthedocs.io/locating-elements.html" rel="nofollow noreferrer">https://selenium-python.readthedocs.io/locating-elements.html</a></p>