java - Java:找不到状态按钮
问题描述
我正在处理 Selenium 中的功能文件,但在尝试读取状态按钮时遇到问题。如果状态符号设置为“已邀请”,则应该切换到不同的管理员帐户应用程序并批准邀请。但是,在这种情况下它没有这样做。有什么建议吗?
public void disconnectFromUser(String user) {
logger.info("Making sure that I am not connected to PurpleHS user");
iframeExit();
searchForUser(user);
communityFrame();
try {
String buttonText = driver.findElement(By.className("cp-ur-link-wrapper ")).findElement(By.tagName("a")).getText();
if (buttonText.equals("Invited")) {
acceptConnectionRequestByHSUser();
searchForUser(user);
communityFrame();
clickDisconnectBtn();
} else {
clickDisconnectBtn();
}
} catch (NoSuchElementException ex) {
logger.info("The user is not a connection.");
driver.findElement(By.className("close")).click();
waitUntilPageFinishLoading();
}
}
这是一些 HTML:
<div id="cp-ur-17417" class="cp-ur-link-wrapper "><a href="#" title="Invited" class="ur-pending ur-request-link ur-disabled-link">Invited</a></div>
解决方案
对于这行代码:
String buttonText = driver.findElement(By.className("cp-ur-link-wrapper ")).findElement(By.tagName("a")).getText();
您可以简单地将其替换为linkText:
String buttonText = driver.findElement(By.linkText("Invited")).getText();
在代码中:
if (buttonText.equals("Invited")) {
System.out.println("Inside if else ladder")
acceptConnectionRequestByHSUser();
searchForUser(user);
communityFrame();
clickDisconnectBtn();
} else {
clickDisconnectBtn();
}
推荐阅读
- javascript - 如何向数组状态添加值?
- ios - 是 StoreKit 的“要求审核”警报部分还是自定义的?
- html - 类 login100-form-title CSS 未显示
- c# - Lambda 表达式到表达式
树(切片 2 - 连接) - python - 使用 rpy2 在 Python 中获取 R 数据框
- r - 即使在 R 中进行记忆,递归也很慢
- javascript - 尝试导入错误:“BrowseRouter”未从“react-router-dom”导出(导入为“Router”)
- r - 检查完美平方并用 R 中的另一个值替换
- r - 使用 ggplot 定义图例
- python - 具有特定数据结构的百分比堆积条形图