Search code examples
javaseleniumwebdrivermodal-dialogsendkeys

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

tried many times to click on [OK] but its not interact with element.

First within Click(). and then within Send Keys and its not worked..

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);

Solution

  • SOLVED BY USING ".perform()"

    act.sendKeys(Keys.ENTER).perform();