package com.test.utils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class Search
{
public static boolean isContentAppeared(WebDriver driver, String content){
boolean status = false;
try{
driver.findElement(By.xpath("//*[contains(.,'" + content + "')]"));
System.out.println(content+ "已找到");
status = true;
}catch (Exception e){
System.out.println(content+ "没有找到");
}
return status;
}
}
@BeforeClass
public void beforeClass() {
System.setProperty("webdriver.ie.driver", "D:\\WebDriver\\IEDriverServer.exe");
DesiredCapabilities ieCapability = new DesiredCapabilities();
ieCapability.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
driver = new InternetExplorerDriver(ieCapability);
//driver.get("http://localhost:8080/day04/demo.html");
driver.get("http://demo.opensourcecms.com/wordpress/wp-login.php");
}
public void login() throws InterruptedException{
driver.findElement(By.id("user_login")).sendKeys("admin");
driver.findElement(By.id("user_pass")).sendKeys("demo123");
driver.findElement(By.id("wp-submit")).click();
Thread.sleep(3000);
//WebElement element = driver.findElement(By.xpath("//ul[@id='adminmenu']/li[3]/div[3]/div/ul/li[2]/a[.='Add New']"));
WebElement element = driver.findElement(By.xpath("//ul[@id='adminmenu']/li[3]/div[3]/div/ul/li[2]/a"));
//WebElement element = driver.findElement(By.xpath("//ul[@id='adminmenu']/li[3]/div[3]/div/ul/a[@contains(text(),'Add New')]"));
Thread.sleep(3000);
Assert.assertTrue(Search.isContentAppeared(driver, "Add New Post"));
}
查找页面中的文字元素
最新推荐文章于 2023-08-03 17:20:44 发布