1 回答
TA贡献1850条经验 获得超11个赞
您可以尝试等待警报消息可见并使用WebDriverWait和visibilityOfElementLocated条件获取文本:
WebDriverWait wait = new WebDriverWait(driver, 5);
String alertMessage = wait.until(ExpectedConditions
.visibilityOfElementLocated(By.cssSelector(".top.alert.danger.fired"))).getText();
如果悬停时警报消息没有消失,您可以尝试Actions悬停moveToElement,然后通过单击关闭按钮获取文本并关闭警报:
WebDriverWait wait = new WebDriverWait(driver, 5);
WebElement alertMessageElement = wait
.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".top.alert.danger.fired")));
Actions actions = new Actions(driver);
actions.moveToElement(alertMessageElement).perform();
String alertMessage = alertMessageElement.getText();
alertMessageElement.findElement(By.cssSelector("button.close")).click();
添加回答
举报