简体   繁体   中英

how to get a class value from text box Webdriver using Java

test condition - to verify the field validation ,ie if i enter a invalid data in that Text box, then capture the Exception value and verify the same (Please enter first name) so, following are my HTML code

Before Execution (validation)

<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>

After Execution of Validation

<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>

how can verify the validation message if exist or not during invalid entry pass in that object

my code is

\\ 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"));

if i execute it always getting "input-txt" class not getting the "input-txt ErrorControl"

Please provide help how to handle this

Thanks

prabu

try to sendKeys(" ") of another invalid symbols. And then use this check:

webdriver.findElement(By.cssSelector("input#txtFirstName")).getAttribute("class").contains("ErrorControl")
String Validationmessage = driver.findElement(
    >               By.cssSelector("input#txtFirstName")).getAttribute("title");

for the above i will got the validation message for that particular Field

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM