如何使用Python + Selenium从警报框中读取文本 [英] How to read the text from the alert box using Python + Selenium
本文介绍了如何使用Python + Selenium从警报框中读取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从警报框中读取文本。
I want to read the text from the alert box.
如果在警报框中找到此文本,则必须关闭警报框:
If this text is found in the alert box I have to close the alert box:
推荐答案
我也有类似情况就像在我的框架中一样,这就是我解决的方法。
I have similar situations as this in my framework as well, and this is how I solved it.
if (_driver.FindElement(By.XPath("//*[text()[contains(.,'No Sales Found')]")).Enabled)
{
//Do Something
}
将此功能放在可能引起错误的功能后面。另外,此示例使用C#和_driver作为驱动程序,这可能与您使用的驱动程序有所不同。
Put this after functionality that may bring the error up. Also, this example is using C# and _driver as the driver, which may be different from what you are using.
这篇关于如何使用Python + Selenium从警报框中读取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文