【发布时间】:2019-03-09 01:37:57
【问题描述】:
无论我使用什么定位器,我都无法单击此按钮,而且我无法理解原因。我使用过 linkText、partialLinkText、x-path、className 等。我在页面对象模型设计模式中使用 PageFactory。
这是按钮所在的 div 的代码:
<div class="clearfix main-page-indent">
<a href="http://automationpractice.com/index.php?controller=address" title="Add an address" class="btn btn-default button button-medium">. <span>Add a new address<i class="icon-chevron-right right"></i></span></a>
</div>
这里是源代码的链接: 查看源代码:http://automationpractice.com/index.php?controller=addresses
您只需先创建一个帐户,它超级快。
以下是我尝试过的两种方法:
1.)
//Page Factory
@FindBy(how = How.PARTIAL_LINK_TEXT, using = "Add an address")
WebElement newAddressBtn;
public AddNewAddressPage clickAddNewAddressBtn() {
newAddressBtn.click();
return new AddNewAddressPage();
}
2.)
@FindBy(xpath = "//a[@href='http://automationpractice.com/index.php?controller=address']")
WebElement newAddressBtn;
有人知道如何整合这个定位器吗?
感谢您的帮助!
【问题讨论】:
-
马上,当根据您的 HTML 的实际链接文本是“添加新地址”时,它不会找到“添加地址”的部分链接文本,但即便如此,该文本在 span 标签内。
-
这个 HTML sn-p 是否在 IFRAME 中?
标签: selenium xpath testng href findby