以下是代码:
driver.navigate().to("https://www.google.com/");
QBOWebPage.wait(2000);
WebElement e = driver.findElement(By.xpath("//input[@name='q']"));
e.sendKeys("Country");
e.sendKeys(Keys.ENTER);
QBOWebPage.wait(4000);
String searchText= e.getText();
Assert.assertEquals(searchText, "Country");
以上断言失败。搜索文本为空字符串。
答案 0 :(得分:0)
我认为解决方法是做这样的事情:
driver.navigate().to("https://www.google.com/");
QBOWebPage.wait(2000);
WebElement e = driver.findElement(By.xpath("//input[@name='q']"));
e.sendKeys("Country");
e.sendKeys(Keys.ENTER);
QBOWebPage.wait(4000);
WebElement f = driver.findElement(By.xpath(".//*[@id='rso']/li[1]/div/h3") );
Assert.assertTrue(f.getText().contains("Country") );