PopUp window 无法点击 Modal window class 下的 OK 按钮 - Selenium [JAVA]
PopUp window not able to click on OK button which Is under Modal window class - Selenium [JAVA]
尝试更改某些数据时显示的弹出窗口。存储在模态对话框window
多次尝试点击[确定],但无法与元素交互。
首先在 Click() 中。
然后在 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>
和源代码[它是打印正文但不是点击确定按钮加回车键]:
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);
您也可以尝试使用 linkText。
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Ok"))).click();
或使用 xpath :
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[text()='Ok'and @id='model-confirmed']"))).click();
试试这个:
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='myModal-vechail']//*[contains(text(),'Ok')]"))).click();
使用“.perform()”解决
act.sendKeys(Keys.ENTER).perform();
尝试更改某些数据时显示的弹出窗口。存储在模态对话框window
多次尝试点击[确定],但无法与元素交互。
首先在 Click() 中。 然后在 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>
和源代码[它是打印正文但不是点击确定按钮加回车键]:
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);
您也可以尝试使用 linkText。
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Ok"))).click();
或使用 xpath :
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[text()='Ok'and @id='model-confirmed']"))).click();
试试这个:
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='myModal-vechail']//*[contains(text(),'Ok')]"))).click();
使用“.perform()”解决
act.sendKeys(Keys.ENTER).perform();