【发布时间】:2020-05-25 10:21:07
【问题描述】:
<button class="md-icon-button md-button md-ink-ripple"
type="button" ng-transclude="" ng-click="hide()">
<i class="fa fa-remove ng-scope"></i>
</button>
步骤定义代码:
@And("^Check whether the Alert message display properly$")
public void alert_msg_display() throws Throwable {
WebElement x= driver.findElement(By.xpath("//button[@data-hover='LOGIN NOW']")); // Path of login button
actionClick(driver, x); // To click login button
WebElement y= driver.findElement(By.xpath("//div[@class='md-dialog-content ng-binding']")); // Path of Alert message text
String a = y.getText();
WebElement z= driver.findElement(By.xpath("//i[@class='fa fa-remove ng-scope']")); // Path of close button of alert popup
waitClick(driver, z); // To wait until close button display
actionClick(driver, z); // Click on close (Note:This operation get FAILED)
String a1 = "Please Enter Branch Id";
driver.findElement(By.xpath("//input[@ng-model='Branchid']")).sendKeys("HO");
actionClick(driver, x);
String b = y.getText();
waitClick(driver, z);
actionClick(driver, z);;
String b1 = "Please Enter Username (Email Id)";
if (a.equals(a1) && b.equals(b1))
test.log(LogStatus.PASS, "Test Case ID: LOG_006 to LOG_010 - Pass");
else
test.log(LogStatus.FAIL, "Test Case ID: LOG_006 to LOG_010 - Fail");
}
跑步者文件
public void actionClick(WebDriver driver, WebElement a) {
Actions action = new Actions(driver);
action.moveToElement(a).click().build().perform();
}
public void waitClick(WebDriver driver, WebElement a) {
WebDriverWait wait = new WebDriverWait(driver,10);
wait.until(ExpectedConditions.visibilityOf(a));
}
我尝试使用.click 方法、Actions 方法、JSExecutor 方法单击按钮,还使用了Wait...但我无法单击按钮。请放下您宝贵的cmets。提前谢谢...
【问题讨论】:
-
请进行代码试用。
-
@DebanjanB 检查已编辑的帖子....
-
@SnowGift 尝试等到警报出现
wait = WebDriverWait(current_user_driver, 5)wait.until(EC.alert_is_present())然后alert = driver.switch_to.alert并接受警报alert.accept() -
@ManaliKagathara 当我使用 driver.switchTo().alert();它显示错误为“没有此类警报”
-
@SnowGift 您可以通过按 Enter 键删除警报 在您的普通浏览器中尝试此操作是否成功?
标签: html selenium selenium-webdriver button css-selectors