我正在测试一个Web应用程序。应用程序中有一个员工注册UI。我想使用selenium web driver测试UI中显示的所有水印是否正确。哪个是用于读取水印值的命令? enter image description here
答案 0 :(得分:0)
嗨,如果我正在思考,那么就像下面这样做假设您想要处理的页面的html源代码如下所示
HTML来源
<input itemprop="query-input" type="search" name="s" placeholder="Search this website 1">
<input itemprop="query-input" type="search" name="s" placeholder="Search this website 2">
<input itemprop="query-input" type="search" name="s" placeholder="Search this website 3">
<input itemprop="query-input" type="search" name="s" placeholder="Search this website 4">
<input itemprop="query-input" type="search" name="s" placeholder="Search this website 5">
<input itemprop="query-input" type="search" name="s" placeholder="Search this website 6">
<input itemprop="query-input" type="search" name="s" placeholder="Search this website 7">
<input itemprop="query-input" type="search" name="s" placeholder="Search this website 8">
<input itemprop="query-input" type="search" name="s" placeholder="Search this website 9">
<input itemprop="query-input" type="search" name="s" placeholder="Search this website 10">
然后请按照下面这样做
public class TestClass {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("file:///C:/Users/rajnish/Desktop/inpuBox.html");
// take everything inside the list like below
List<WebElement> myInputBoxes = driver.findElements(By.name("s"));
// now to print the place holder run a for loop
for(int i=0;i<myInputBoxes.size();i++){
System.out.println("PlaceHolder is : " + myInputBoxes.get(i).getAttribute("placeholder"));
}
}
}