简体   繁体   English

如何使用Java从文本框Webdriver获取类值

[英]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 测试条件-验证字段验证,即,如果我在该文本框中输入了无效数据,然后捕获Exception值并进行验证(请输入名字),那么以下是我的HTML代码

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" 如果我执行它总是得到“ input-txt”类而不得到“ input-txt ErrorControl”

Please provide help how to handle this 请提供有关如何处理此问题的帮助

Thanks 谢谢

prabu 普拉布

try to sendKeys(" ") of another invalid symbols. 尝试发送另一个无效符号的sendKeys(" ") 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 对于上述,我将获得该特定字段的验证消息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Selenium WebDriver(Java)从AJAX文本框中选择值 - Select value from AJAX text box using Selenium WebDriver (Java) 如何从中获取价值<h1>在 Selenium WebDriver、Java 中使用类标记 - How to get value from <h1> tag using class in Selenium WebDriver, Java 无法使用Java / webDriver中的选择类更改选择框值 - Not able to change select box value using select class in Java/webDriver 如何通过与Java一起使用Selenium WebDriver从此HTML代码中获取文本 - How to get Text from this HTML code By using Selenium WebDriver with Java 在Selenium WebDriver中使用Java在ID或任何属性中不存在值时如何从禁用的文本字段中获取值 - How to get value from a disabled text field when the value is not present in ID or in any attribute using Java in Selenium WebDriver 是否可以使用Java使用Selenium WebDriver从验证码图像中获取文本? - Is it possible to get text from captcha image with Selenium WebDriver using Java? 使用Robot类和Selenium WebDriver将大写文本发送到文本框 - Send caps text to a text box using Robot class & Selenium WebDriver 如何使用带有Java的Selenium Webdriver从登录页面上的图像徽标获取文本 - how to get text from image logo on Login page using Selenium Webdriver with java 如何使用带有Java的Selenium Webdriver从包围在多个span标签中的span元素中获取实际文本 - How to get the actual text from a span element enclosed within multiple span tags, using Selenium Webdriver with Java 如何使用Java在WebDriver中获取按钮的标题/文本 - How to get caption/text of button in WebDriver using Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM