<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>
StepDefinition代码:
@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
...但是我无法单击按钮。请放弃您的宝贵意见。预先感谢...
答案 0 :(得分:1)
从我的观察来看,很明显这不是正常的浏览器警报(如果是,那么我们将无法检查其中的元素),因此与硒警报相关的代码在这里将无法正常工作(例如驱动程序)。 switchToAlert()将引发“否”警报。
尝试使用以下代码段单击,它可能会起作用
WebElement z= driver.findElement(By.xpath("//button[@class='md-icon-button md-button md-ink-ripple']"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].click();", z);
答案 1 :(得分:1)
应在按ESCAPE键时进行操作。请尝试以下: 以下两种方法可以起作用:
获取该图像的元素定位器->将Escape发送到元素。
WebElement loginimg = driver.findElement(By.id(“ AlertX”));; loginimg.sendKeys(Keys.ESCAPE);
或
您可以按如下所示按Java Robot类按Escape键:
导入java.awt.Robot;导入java.awt.event.KeyEvent;
Robot r = new Robot(); r.keyPress(KeyEvent.VK_ESCAPE);
r.keyRelease(KeyEvent.VK_ESCAPE);