我已经编写了代码来验证没有定位器的文本和可见性。请各位大侠指教,这是正确的方法吗?
如果有任何替代方法,那么您的建议将不胜感激。
public class TextVisibility {
WebDriver driver = new FirefoxDriver();
public static String baseUrl = "website url";
public String client = "your search string";
public void visibilityOfText(){
driver.get(baseUrl);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
WebElement element = driver.findElement(By.cssSelector("body"));
boolean feedBack = driver.findElement(By.cssSelector("body")).getText().contains(client);
boolean feedbackVisible = element.isDisplayed();
if(feedBack==true){
System.out.println(client+ "is present");
if(feedbackVisible==true){
System.out.println(client+ "is visible");
}
else{
System.out.println(client+ "is not visible");
}
}
else{
System.out.println(client+ "is not present");
}
driver.close();
driver.quit();
}
}