Issue
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
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 :D
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']
Answered By - Shawn
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.