[英]Can't get WebElement tag name using Selenium
I have a popup page that I need to click a button on. 我有一个弹出页面,需要单击一个按钮。 The popup page is in Angular.
弹出页面位于Angular中。
The button I need to click is: 我需要单击的按钮是:
<button _ngcontent-c8="" class="btn btn-primary" type="button">Apply</button>
The path the method calls take to click the button is as follows: 该方法调用单击按钮所采用的路径如下:
TemplatePopupPage templatePopupPage = editTemplatePage.clickApplyToClientsButton();
pause(5000);
editTemplatePage = templatePopupPage.clickApplyButton(EditTemplatePage.class);
@SuppressWarnings("unchecked")
public <W> W clickClientSearchApplyButton(Class<W> expectedPage) throws Exception {
click(clientsApplyButton);
pause(2000);
return (W) expectedPage.getConstructors()[0].newInstance();
}
protected void click(WebElement element) {
String tagName = element.getTagName();
String attributeType = element.getAttribute("type");
if (tagName.equals("input")
&& (attributeType.equals("submit"))) {
element.submit();
return;
}
element.click();
}
public interface WebElement {
void click();
}
I've tried a couple xpaths which all point to the button successfully, such as: 我已经尝试了几个xpath,它们都成功指向了按钮,例如:
@FindBy(xpath = "//div[@class='modal-footer']/button[text()='Apply']")
protected WebElement clientsApplyButton;
It keeps failing at the line - String tagName = element.getTagName();
它不断失败-
String tagName = element.getTagName();
in the click() method. 在click()方法中。 The error message is
java.lang.NullPointerException
错误消息是
java.lang.NullPointerException
I don't think it's an issue with the XPath as when I inspect the page, the XPath finds the element on page. 我认为这与XPath无关,因为当我检查页面时,XPath会在页面上找到元素。 And now other element exists with that xpath.
现在,其他元素与该xpath存在。
I have a feeling it has something to with the _ngcontent-c8 attribute, because I am able to click buttons on other pages using that same click()
method 我感觉它与_ngcontent-c8属性有关,因为我可以使用相同的
click()
方法click()
其他页面上的按钮
也许您可以尝试一下: @FindBy(xpath = "//div[@class='modal-footer']/button[con]") protected WebElement clientsApplyButton;
i have a try in my IDE,it can work out.this is screenshot 我可以在IDE中尝试一下,可以解决问题。这是屏幕截图
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.