Selenium @FindBy linkText或@FindBypartialLinkText不起作用
我正在为自动化工作,我试图单击一个元素,该元素没有id,类名,因此我正在使用xpath.为了改善我的代码,我想通过href找到该元素,所以我在使用:
I'm working for automation, I'm trying to click on an element ,this element has no id, classname so I'm using the xpath. To improve my code I would like to find this element by href, so I'm using:
@FindBy(linkText="Transfer")
WebElement transferBtn;
我也尝试过:
@FindBy(partialLinkText="Transfer")
WebElement transferBtn;
但是我的代码找不到webElement,它适用于其他href,但不是全部.我认为问题出在开发人员工具上,我将向您展示该元素:
But my code doesn't find the webElement, it's working for other href but not all. I think the problem is developer tools, i'll show you the element:
<a href="#">My transfer</a>
您对问题有任何想法,为什么它不起作用? 谢谢.
Do you have any idea of the problem, why it's not working? Thanks.
根据您共享的 HTML ,您可以使用以下任一解决方案:
As per the HTML you have shared you can use either of the following solutions:
-
linkText
:
@FindBy(linkText = "My transfer")
WebElement transferBtn;
partialLinkText
:
@FindBy(partialLinkText = "transfer")
WebElement transferBtn;
xpath
:
@FindBy(xpath = "//a[contains(.,'My transfer')]")
WebElement transferBtn;