使用C#进行Selenium Web应用程序测试

时间:2016-10-21 05:54:52

标签: c# selenium selenium-webdriver

我正在尝试断言我的网络应用程序中的文本字段是否为空,但我不知道该怎么做。这里的一点帮助可以提供帮助。提前致谢

2 个答案:

答案 0 :(得分:0)

获取文字字段的属性值: -

 String expectedvalue="your expected value";
 WebElement element=driver.findElement(By.xapth("path of your element")).sendkey("Actual value");
 String attributevalue=element.getAttribute("Value");

 System.out.println(attributevalue);

  if(attributevalue.equals(expectedvalue)){
    //Text box is not empty
}
  else{
    //textbox is empty

    }

注意:-code是用C#

中的java更改编写的

答案 1 :(得分:0)

首先,您需要获取表示文本字段的元素。 然后,您可以将其存储在IWebElement变量中。 所以:

module.exports = function (dep1, dep2) {
// private methods

   return {
    // public methods
       test: function(){...}
   }
}

现在,您可以在将IWebElement转换为字符串后将此值与预期值(即空)进行比较。

IWebElement element = driver.FindElement(By.xpath("//div[@textField='text']")).Text;