我有这个html代码,我想用Selenium进行测试:
我想得到所有div层洞察div boxes
我怎么能这样做?
RemoteWebDriver driver = BrowserFactory.getDriver(" chrome"," C:\ Program Files(x86)\ Google \ Chrome \ Application \ chromedriver.exe");
driver.get("http://jenkins.mws.com:8080");
driver.switchTo().frame("iwg-game-full");
WebDriverWait waitPage = new WebDriverWait(driver, 20);
WebElement element = new WebDriverWait(driver, 20).until(steadinessOfElementLocated(By.id("ready")));
element.click();
if (element.isDisplayed())
{
System.out.println("Play button is displayed");
TimeUnit.SECONDS.sleep(5);
List<WebElement> childs = driver.findElements(By.xpath("div[id='boxes'] div"));
for (int i = 0; i < childs.size(); i++)
{
WebElement get = childs.get(i);
get.getText();
System.out.println(">>>>> getText " + get.getText() + " " + get.getTagName());
}
}
答案 0 :(得分:1)
在"//div[@id='boxes']//div"
方法中使用xpath - "div[id='boxes'] div"
或css driver.findElements(By.....)
。