【发布时间】:2021-08-05 14:52:46
【问题描述】:
我在 Selenium 中的代码:
driver.findElement(By.xpath("//a[@href='/agent-create-profile'][1]")).click();
它给出错误:线程“main”中的异常org.openqa.selenium.NoSuchElementException:没有这样的元素:无法找到元素:{“method”:“xpath”,“selector”:“//a [@href ='/agent-create-profile'][1]"}
Selectors hub 显示 4 个与提供的 xpath 匹配的元素:
<a tabindex="0" class="primary-button__PrimaryButton-iSIsNJ cjTSCX abstract-button abstract-button--size-large" href="/agent-create-profile" style="" xpath="2"> Create Profile </a>
<a tabindex="0" class="primary-button__PrimaryButton-iSIsNJ cjTSCX abstract-button abstract-button--size-large" href="/agent-create-profile" style="" xpath="3"> Let's start </a>
<a tabindex="0" class="primary-button__PrimaryButton-iSIsNJ cjTSCX abstract-button abstract-button--size-large" href="/agent-create-profile" style="" xpath="4"> Agent Sign up </a>
<a rel="noopener noreferrer" class="navigation-section__menu-link" href="/agent-create-profile" style="" xpath="4"></a>````
Below is the html code:
````<a tabindex="0" class="primary-button__PrimaryButton-iSIsNJ cjTSCX abstract-button abstract-button--size-large" href="/agent-create-profile" style="" xpath="1">Sign up</a>````
【问题讨论】: