擅长:python、mysql、java
<p>您需要执行两个步骤:
一。按链接文本获取元素
2。从该元素获取id的属性值</p>
<p>您可以尝试类似于以下代码的方法来创建函数:
(注意:下面的代码是JAVA,您需要编写类似的python代码)</p>
<pre><code>WebElement ele = driver.findElement(By.linkText("Forgot Password"));
ele.getAttribute("id");
</code></pre>
<p>以下链接可作为参考:</p>
<p><a href="https://stackoverflow.com/questions/12516542/how-to-grab-just-element-id-using-selenium-webdriver-2">How to grab just element id - using Selenium WebDriver 2</a></p>
<p><a href="http://www.software-testing-tutorials-automation.com/2014/01/how-to-locate-element-by-link-text-or.html" rel="nofollow noreferrer">http://www.software-testing-tutorials-automation.com/2014/01/how-to-locate-element-by-link-text-or.html</a></p>