[英]PopUp window not able to click on OK button which Is under Modal window class - Selenium [JAVA]
a popup that displayed while tried to change some data.尝试更改某些数据时显示的弹出窗口。 that stored on Modal Dialog window
存储在模态对话框 window
tried many times to click on [OK] but its not interact with element.多次尝试单击 [确定] 但它不与元素交互。
First within Click().首先在 Click() 中。 and then within Send Keys and its not worked..
然后在 Send Keys 中并且它不起作用..
div class="modal show" id="myModal-vechail" aria-modal="true" style="padding-right: 17px; display: block;"> <div class="modal-body bg-white"> <div class="row"> <div class="col-12 pt-2">You have changed vehicle model. Would you like to proceed?</div> <div class="col-12"> <div class="row pt-3 pb-2 justify-content-center"> <a href="javascript:void(0)" id="model-confirmed" tabindex="null" class="col-md-3 btn btn-primary btn-lg mr-md-3 step-control">Ok</a> <a href="javascript:void(0)" id="changeModelPopupCancel" tabindex="null" class="col-md-3 btn btn-primary btn-lg step-control" data-dismiss="modal">Cancel</a> </div> </div> </div> </div> </div>
and the source Code [ it is print the Body Text But not clicking on Ok button plus the Enter Key] :和源代码[它是打印正文但不点击确定按钮加回车键] :
String s1= driver.findElement(By.xpath("//*[@id='myModal-vechail']/div/div/div[1]")).getText();
System.out.println(s1);
WebDriverWait wait = new WebDriverWait(driver, 2);
Thread.sleep(2000);
//driver.findElement(By.id("model-confirmed")).click();
Actions act = new Actions(driver);
act.sendKeys(Keys.TAB ).perform();
act.sendKeys(Keys.ENTER);
You could try with linkText as well.您也可以尝试使用linkText 。
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Ok"))).click();
or with xpath:或使用 xpath:
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[text()='Ok'and @id='model-confirmed']"))).click();
Try this:尝试这个:
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='myModal-vechail']//*[contains(text(),'Ok')]"))).click();
SOLVED BY USING ".perform()"通过使用“.perform()”解决
act.sendKeys(Keys.ENTER).perform();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.