C# 用C语言测试Selenium web应用程序#
我试图断言我的web应用程序中的文本字段是否为空,但我不知道该怎么做。这里的一点帮助可能会有所帮助。提前感谢获取文本字段的属性值:-C# 用C语言测试Selenium web应用程序#,c#,selenium,selenium-webdriver,C#,Selenium,Selenium Webdriver,我试图断言我的web应用程序中的文本字段是否为空,但我不知道该怎么做。这里的一点帮助可能会有所帮助。提前感谢获取文本字段的属性值:- String expectedvalue="your expected value"; WebElement element=driver.findElement(By.xapth("path of your element")).sendkey("Actual value"); String attributevalue=element.getAttrib
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
}
注意:-代码是用java编写的,在C#中更改文本字段的Get属性值:-
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
}
注意:-代码是用java编写的,更改为C#首先需要获取表示文本字段的元素。 然后可以将其存储在IWebElement变量中。 因此: 现在,在将IWebElement转换为字符串后,可以将该值与期望值(即空)进行比较
IList<string> comparison = new List<string>();
foreach(var element in driver.FindElements(By.xpath("yourXpath"));
{
comparison.Add(element.Text);
}
Assert.AreEqual(comparison, "")
IList比较=新列表();
foreach(driver.FindElements中的var元素(By.xpath(“yourXpath”));
{
比较。添加(元素。文本);
}
Assert.AreEqual(比较,“”)
首先需要获取表示文本字段的元素。
然后可以将其存储在IWebElement变量中。
因此:
现在,在将IWebElement转换为字符串后,可以将该值与期望值(即空)进行比较
IList<string> comparison = new List<string>();
foreach(var element in driver.FindElements(By.xpath("yourXpath"));
{
comparison.Add(element.Text);
}
Assert.AreEqual(comparison, "")
IList比较=新列表();
foreach(driver.FindElements中的var元素(By.xpath(“yourXpath”));
{
比较。添加(元素。文本);
}
Assert.AreEqual(比较,“”)