我是Selenium的初学者,只是我想检查网站的搜索工作是否正常。意味着当我在搜索框中输入任何关键字并单击搜索时,它会提供正确的搜索结果。如何使用Selenium WebDriver进行检查。请指导我。
答案 0 :(得分:0)
您应该提供有关查询的更多详细信息 例如,您应该包含您正在处理的URL或您正在使用的URL的类似URL
答案 1 :(得分:0)
您可以使用搜索结果页面中的项目属性作为测试的断言点
尝试以下代码
package StackOverFlow.StackOverFlow;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.Test;
public class App
{
@Test
public void test () throws InterruptedException{
System.setProperty("webdriver.chrome.driver", "C:\\Chrome\\2\\chromedriver.exe");
WebDriver Dr = new ChromeDriver();
Dr.manage().window().maximize();
Dr.get("http://www.conns.com");
Thread.sleep(4000);
WebElement ele = Dr.findElement(By.xpath(".//*[@id='search']"));
ele.sendKeys("furniture");
ele.sendKeys(Keys.ENTER);
Thread.sleep(4000);
String result= Dr.findElement(By.xpath("/html/body/div[3]/div/div[4]/div[2]/div/div[1]/h1")).getText();
Assert.assertEquals("Furniture & Mattresses", result);
}
}
我在页面上使用了一个非常明显的元素(Furniture& Mattresses)来对其文本进行断言