You could try this:
JavascriptExecutor js= (JavascriptExecutor) driver;
WebElement webElement=driver.findElement(By.cssSelector("div.modal-footer button.btn.btn-default"));
js.executeScript(“arguments[0].click()”, webElement);
Hope it helps.
By.xpath(".//button[.='/"Submit/"'])
or
By.xpath(".//button[@class='btn btn-default'])
If it found but click doesnt work try that javascript from other comment
尝试下面的xpath
:
driver.findElement(By.xpath("//div[@class='modal-footer']//button[contains(@class,'btn-default')]")).click();
try Alert alert = driver.switchTo().alert(); alert.accept();
Alert alert = driver.switchTo().alert(); alert.accept();
or
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
before your actual code for modal window to load
or if these dont work, can you share the error in your console
I presume you are able to identify the element.However unable to click on that. Try use following options.
WebDriverWait
and elementToBeClickable
to click on the element. WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement elementBtn = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.modal-footer button.btn.btn-default")));
elementBtn.click();
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement elementBtn = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.modal-footer button.btn.btn-default")));
Actions action=new Actions(driver);
action.moveToElement(elementBtn).click().build().perform();
JavascriptExecutor js= (JavascriptExecutor) driver;
js.executeScript("arguments[0].click();", driver.findElement(By.cssSelector("div.modal-footer button.btn.btn-default")));
Note : If above all options doesn't work.Check if there any iframe
avaialable.If so, you need to switch to iframe first.like below.
driver.switchTo().frame("framename"); //name of the iframe.
driver.switchTo().frame(0); //you can use index as well.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.