模态弹出窗口无法点击按钮-java selenium

问题描述 投票:0回答:1

弹出窗口会在 6-7 秒后出现,但无法单击加入按钮或输入文本,任何人都可以为此发送代码吗? https://www.guru99.com/learn-sap-testing-create-your-first-sap-test-case.html

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(15));
WebElement modalWindow = wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("cb-box__inner-bg")));

// Check if the modal window is displayed
if (modalWindow.isDisplayed()) {
    System.out.println("Modal window is displayed.");
    WebElement closeButton = modalWindow.findElement(By.className("cb-form-group__btn.ff-inherit")); // Correct class name
    closeButton.click();

    // Wait for the modal window to close
    wait.until(ExpectedConditions.invisibilityOfElementLocated(By.className("cb-box__inner-bg"))); 
    System.out.println("Modal window is closed.");} 
else {
    System.out.println("Modal window is not displayed.");
}

// Close the WebDriver session
driver.quit();
java selenium-webdriver popup
1个回答
0
投票
no such element: Unable to locate element: {"method":"css selector","selector":".cb\-form\-group__btn\.ff\-inherit"}

您收到此异常的原因是由于以下行。我找不到任何与类名匹配的元素

cb-form-group__btn.ff-inherit

WebElement closeButton = modalWindow.findElement(By.className("cb-form-group__btn.ff-inherit"));

请参阅下面的完整工作代码:

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(300));
WebElement modalWindow = wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("cb-box__inner-bg")));

// Check if the modal window is displayed
if (modalWindow.isDisplayed()) {
    System.out.println("Modal window is displayed.");
    WebElement closeButton = modalWindow.findElement(By.xpath("(//div[@class='cb-close'])[1]"));
    closeButton.click();

    // Wait for the modal window to close
    wait.until(ExpectedConditions.invisibilityOfElementLocated(By.className("cb-box__inner-bg"))); 
    System.out.println("Modal window is closed.");} 
else {
    System.out.println("Modal window is not displayed.");
}

// Close the WebDriver session
driver.quit();
© www.soinside.com 2019 - 2024. All rights reserved.