如何在运行时验证 n 个<p>标签?



我在<div>标签下有<p>标签列表,并希望为任何更改验证所有标签。HTML代码在下面参考。

几个<p>标签具有子标签,很少有标签。如何使用WebDriver验证所有及其内容的<p>标签?

<div class="content content_login">
<img id="ctl00_MainContent_imgBanner" class="banner" src="../App_Themes/bsi/images/logo/banner_bsi.jpg" style="border-width:0px;">
            
<p><span id="ctl00_MainContent_lblPageContent"></span></p>
<p><strong>Important Notes: </strong>    Welcome to MyLoanWeb.com! If this is your first time visiting our new site, please 
<a href="AccountVerification.aspx">enroll for account access.</a> Accounts from loanlink.bsifinancial.com will not be valid unless they are re-enrolled.    </p> 
<p><strong>If you are experiencing any trouble receiving our emails or clicking on any of the links in the emails, please review our 
<a href="Help.aspx#Email">troubleshooting email issues</a> guide:</strong></p>
<p><strong>Please contact us if you have any questions about our services:</strong></p>
<p>ABC FinCorp Services</p>
<p>P.O. Box 456789</p> 
<p>Testville, PA</p>
<p>Customer Care Phone: 800-327-7861 </p> 
<p style="padding-bottom:0px;">Customer Care Fax: 814-217-1366</p>
</div>

您不提及您正在使用的语言,所以这是我尝试在Java中做的事情:

WebElement parent = driver.findElement(By.cssSelector("div.content.content_login");
List<WebElement> paragraphs = parent.findElements(By.tagName("p"));

为了验证段落的内容,您必须从每个段落列表项目中提取可见文本,然后验证它们。

现在,所有这些都假定这些段落都是DIV的子元素,并且您不会遇到任何等待问题。您可能需要进行一些调整。

请参阅:何时以及如何使用Selenium WebDriver通过tagName找到元素?请用示例

解释

最新更新