如何检查页面源中是否存在大文本。 我已经使用了contains方法来检查但条件变得错误,因为序列不准确。 我想解决方法如何检查数据是否存在而不是打扰序列
public void demo()
{
String description="(Large data is present)";
String pagesource=driver.getPageSource(); //have also tried with String source = driver.findElement(By.tagName("body")).getText(); String source = driver.findElement(By.tagName("html")).getText();
if(pagesource.contains(description))
{ System.out.println("Match Found"); }
else
{ System.out.println("Match Not Found"); }
}
答案 0 :(得分:0)
似乎是字母区分大小写的问题,请尝试条件:
if(pagesource.toLowerCase().contains(description.toLowerCase()))
{
System.out.println("Match Found");
}
else
{
System.out.println("Match Not Found");
}
在上面,将所有字符转换为两个字符串的小写然后进行比较。
答案 1 :(得分:0)
如果您想在特定位置进行交叉检查数据,那么最好尝试使用gettext();以下示例将以两种方式帮助您
WebDriver driver=new FirefoxDriver();
driver.get("http://seleniumtrainer.com/components/buttons/");
driver.findElement(By.id("button1")).click();
//by using if condition with cross check
try{
if(driver.findElement(By.id("demo")).isDisplayed()==true){
System.out.println("clicked correctly");
}
}catch(Exception e){
System.out.println("U Clicked Button1 text is not displayed. so failing or throwing again to fail test");
throw new Exception(e.getMessage());
}
//simply by using testng assertion
//Assert.assertEquals(driver.findElement(By.id("demo")).getText(), "U Clicked Button1");
//using page source
String pagesource=driver.getPageSource();
if(pagesource.contains("U Clicked Button1")){
System.out.println("search done correctly from page source");
}else{
System.out.println("not found in page source");
}
由于