简体   繁体   English

如何验证搜索结果是否有多个结果?

[英]How to verify if search result has more than one result?

Can anyone please help how to find a search result has more than one results using selenium and TestNG. 谁能帮忙找到使用硒和TestNG的搜索结果不只一个的搜索结果。 Scenario is as follows: 方案如下:

  1. Launch www.amazon.com 启动www.amazon.com
  2. Enter search string in search box and click search 在搜索框中输入搜索字符串,然后单击搜索

Now verify search result has more then 1 result(>1). 现在,验证搜索结果中是否有1个以上结果(> 1)。 Following is the line which I thought of Assert.assertEquals(actual, expected, delta); 以下是我想到的Assert.assertEquals(actual, expected, delta); . Is this the right approach? 这是正确的方法吗?

Try the below code. 试试下面的代码。 It fetches all the search results and then checks if the count is greater than 1 or not, then prints accordingly. 它获取所有搜索结果,然后检查计数是否大于1,然后进行相应打印。 :- :-

    driver.get("http://www.amazon.in/");

    driver.findElement(By.id("twotabsearchtextbox")).sendKeys("bagsasdfafds");

    int count = driver.findElements(By.className("suggest_link")).size();

    Assert.assertTrue(count>=1);
    System.out.println("Count is greater than or equal to 1. Count is: "+count);//This line will ONLY be printed if the count is greater than or equal to 1.

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM