问题: 我收到“NoSuchElementException:无法定位元素错误”。
我的程序生成异常的源代码: 最后一行代码生成以下错误: OpenQA.Selenium.NoSuchElementException:“没有这样的元素:无法定位元素:{“method”:“css选择器”,“selector”:“#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"));
问题 Selenium 可以找到第一行的 DeleteModalPopUpFooter,但不能找到页脚内的按钮,这是怎么回事?我不明白我在忽略什么
我尝试通过以下方式找到按钮:
截图中的代码:
<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>
我无法找到的按钮是最后一个元素
class="btn btn-warning bootstrap4-dialog-button" id="9c4317a1-14bf-47e4-b789-078325377193">Löschen</button>
感谢您的宝贵时间。
PS:第一次在这里发帖,对软件开发还是个新手,所以请温柔一些:D
我试图在模态上找到一个按钮。 Selenium 无法找到按钮
很可能
ID=00d43143-fd7b-4e93-89a2-c48370d9a875
,这个值是动态的。即每次加载页面时值都会发生变化。
为什么不构建一个如下所示的 XPATH 表达式,
找到Abbruch:
//button[text()='Abbruch']
找到Löschen:
//button[text()='Löschen']