【问题标题】:how to get a class value from text box Webdriver using Java如何使用Java从文本框Webdriver获取类值
【发布时间】:2013-10-11 12:45:27
【问题描述】:

测试条件 - 验证字段验证,即如果我在该文本框中输入无效数据,然后捕获异常值并验证相同(请输入名字)所以, 以下是我的 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”

请提供帮助如何处理此问题

谢谢

普拉布

【问题讨论】:

    标签: java selenium-webdriver


    【解决方案1】:

    尝试sendKeys(" ") 的另一个无效符号。然后使用这个检查:

    webdriver.findElement(By.cssSelector("input#txtFirstName")).getAttribute("class").contains("ErrorControl")
    

    【讨论】:

    • 感谢重播,当我执行它时,我总是得到 False
      Boolean er = driver.findElement(By.cssSelector("input#txtFirstName")) .getAttribute("class ").contains("错误控制");
      然后我将其更改为 String Like
      String er = driver .findElement(By.cssSelector("input[name =txtFirstName]")) .getAttribute("class");
      它作为 input-txt 产生的结果也没有得到那个 ErrorControl,让我知道它需要任何额外的东西
    【解决方案2】:
    String Validationmessage = driver.findElement(
        >               By.cssSelector("input#txtFirstName")).getAttribute("title");
    

    对于上述内容,我将获得该特定字段的验证消息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-05
      • 2016-04-29
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 2014-05-28
      • 2016-06-13
      相关资源
      最近更新 更多