![](/img/trans.png)
[英]Select value from AJAX text box using Selenium WebDriver (Java)
[英]how to get a class value from text box Webdriver using Java
測試條件-驗證字段驗證,即,如果我在該文本框中輸入了無效數據,然后捕獲Exception值並進行驗證(請輸入名字),那么以下是我的HTML代碼
執行前(驗證)
<input type="text" class="input-txt" data-bind="value: FirstName" id="txtFirstName"
title="Please enter first name" data-orig-title="">
<span class="f-req" style="display: none;"></span>
執行驗證后
<input type="text" class="input-txt ErrorControl" data-bind="value:
FirstName"id="txtFirstName" title="Please enter first name" data-orig-title="">
<span class="f-req" style="">Please enter first name</span>
在該對象的無效輸入過程中,如何驗證驗證消息是否存在
我的代碼是
\\ passing empty value so its thrown an error message
firstname.sendKeys("");
\\checking if the "input-txt ErrorControl" class are enabled or not
System.out.println("class name" + firstname.getAttribute("class"));
如果我執行它總是得到“ input-txt”類而不得到“ input-txt ErrorControl”
請提供有關如何處理此問題的幫助
謝謝
普拉布
嘗試發送另一個無效符號的sendKeys(" ")
。 然后使用此檢查:
webdriver.findElement(By.cssSelector("input#txtFirstName")).getAttribute("class").contains("ErrorControl")
String Validationmessage = driver.findElement(
> By.cssSelector("input#txtFirstName")).getAttribute("title");
對於上述,我將獲得該特定字段的驗證消息
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.