Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C# Selenium Unable to locate Button in Modal – not an Iframe

The Problem:
I get a "NoSuchElementException:Unable to locate element error".

The Source Code of my Program which generates the Exception:
The last line of code generates, the following error:
OpenQA.Selenium.NoSuchElementException: "no such element: Unable to locate element: {"method":"css selector","selector":"#\30 0d43143-fd7b-4e93-89a2-c48370d9a875"}

IWebElement DeleteModalPopUpFooter = existingChromeDriver.FindElement(By.XPath("/html/body/div[6]/div/div/div[3]"));
IWebElement DeleteButton = DeleteModalPopUpFooter.FindElement(By.Id("00d43143-fd7b-4e93-89a2-c48370d9a875"));

Question
How is it, that Selenium can locate the DeleteModalPopUpFooter, first line, but not the button within the footer? I don’t understand what I am overlooking

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried to locate the button via:

  • XPath
  • ID
  • Name

The Picture shows the HTML Code of the Modal.
Browser Source Code of the Modal

The Code in the Screenshot:

<div class="modal-content">
    <div class="modal-header">
        <div class="bootstrap-dialog-header">
            <div class="bootstrap-dialog-title" id="cd8fac22-96a4-4ce5-a185-dcee905e2c7b_title">Löschen</div>
            <div class="bootstrap-dialog-close-button" style="display: none;"><button class="close"
                    aria-label="close">×</button></div>
        </div>
    </div>
    <div class="modal-body">
        <div class="bootstrap-dialog-body">
            <div class="bootstrap-dialog-message">Wollen Sie diesen Eintrag wirklich löschen ?</div>
        </div>
    </div>
    <div class="modal-footer" style="display: block;"><button class="btn btn-secondary bootstrap4-dialog-button"
            id="2e70b9f9-288b-4081-b5e3-3476b3c16584">Abbruch</button><button
            class="btn btn-warning bootstrap4-dialog-button" id="9c4317a1-14bf-47e4-b789-078325377193">Löschen</button>
    </div>
</div>

The Button I am not able to locate is the very last element
class="btn btn-warning bootstrap4-dialog-button" id="9c4317a1-14bf-47e4-b789-078325377193">Löschen</button>

Thank you for your time.

PS: First time posting here ever and new to software development, so please be gentle 😀

I tried to locate a button on a modal.
Selenium is not able to locate the button

>Solution :

Most likely ID=00d43143-fd7b-4e93-89a2-c48370d9a875, this value is dynamic. i.e. value changes each time the page gets loaded.

Why don’t you construct an XPATH expression as below,

To locate Abbruch:

//button[text()='Abbruch']

To locate Löschen:

//button[text()='Löschen']
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading