这里有两个div
<div class="th_pr"><input id="user_email" class="accounts_input" type="text" size="30" placeholder="Email" name="user[email]"></input><p class="accounts_error_text" style="display: block;">
email is invalid
</p></div>
<div class="th_pr"><input id="user_password" class="accounts_input" type="password" size="30" placeholder="Password" name="user[password]" autocomplete="off"></input><p class="accounts_error_text" style="display: block;">
password can't be blank
</p></div>我需要得到这些元素的文本“电子邮件是无效的”和“密码不能是空白”的文本,因为它将不同的输入。
我一直试图使用xpath来完成这个任务:
By.xpath("//p[contains(.,'email is invalid')]")和
By.xpath("//p[contains(.,'password be blank')]")但我什么都没得到。
resultEmail = ExpectedConditions.invisibilityOfElementLocated(By.xpath("//p[contains(.,'email is invalid')]")).apply(driver);返回true,尽管元素是可见的。
请帮帮忙。
发布于 2013-08-07 07:55:04
请试试这个:
WebElement userEmailErrorMessage = driver.findElement(By.cssSelector("div[class=\"th_pr\"]:nth-child(1) > p"));
WebElement userPasswordErrorMessage = driver.findElement(By.cssSelector("div[class=\"th_pr\"]:nth-child(2) > p"));使用这些元素,您将能够读取相应输入控件的错误消息。
https://stackoverflow.com/questions/18096835
复制相似问题