Selenium - cannot click on an element inside a modal

前端 未结 2 2078
刺人心
刺人心 2021-01-26 12:10

I am using Selenium and java and I cannot click on an element inside a modal. The scenario is this: after clicking on an item inside a frame, it opens up a modal and I need to c

相关标签:
2条回答
  • 2021-01-26 12:56

    I fixed it using jquery inside my script;

    here is the linecode:

    js.executeScript("$('#saveexit').trigger('click');");

    I hope it can help someone in future.

    I dont know why plain javascript was not working...

    0 讨论(0)
  • 2021-01-26 13:03

    As you are using the Selenium-Java clients as per best practices the first and foremost trial must be with invoking the highly efficient and proven click() method. Depending on the errors resulting out of click() method we can work on other alternate solutions.

    As I can see from your code trials with JavascriptExecutor and switchTo().window(), you havn't identified the WebElement representing the SAVE AND EXIT button well.

    To click on the SAVE AND EXIT button you can use the following code block :

    new WebDriverWait(driver, 5).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='modal-dialog']//div[@class='modal-footer']//button[@class='btn modal-button full-btn' and @id='saveexit']"))).click();
    
    0 讨论(0)
提交回复
热议问题