我无法点击子菜单..尝试使用不同的xpath / id .....
下面是html标签,主菜单是演示文稿(用红色箭头标记),子菜单在div下面。
你可以告诉我怎样才能为此写xpath。我想点击子菜单中的假设。
此处主菜单标签位于div(子菜单)的底部。
还附上了硒代码。请帮帮我....
<div id="presentations" class="ToolbarSubMenu" align="left"
父= “presentations_parent” &GT;
<a id="hypothetical" class="ToolbarMenu" href="">Hypothetical</a><br/>
</div>
<a id="presentations_parent" class="ToolbarMenu" href="">Presentations</a>
@Test
public void hypothetical()
{
WebElement ic = driver.findElement(By.id("presentations"));
Actions act = new Actions(driver);
// act.moveToElement(ic).click().build().perform();
//act.moveToElement(ic).doubleClick().build().perform();
act.moveToElement(ic).clickAndHold().release().build().perform();
//ic.click();
//driver.switchTo().window(myWindowHandle);
// driver.findElement(By.linkText("Hypothetical")).click();
// driver.findElement(By.xpath("//div[2][@id='presentations']/a[1]")).click();
//Actions act = new Actions(driver);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// WebElement hyp=driver.findElement(By.partialLinkText("Hypothetical"));
WebElement hyp=driver.findElement(By.id("//div[@id='presentations']/a[1]"));
//act.moveToElement(hyp).click().build().perform();
hyp.click();
答案 0 :(得分:0)
driver.findElement(By.id("presentations")).click();
WebElement hyp = driver.findElement(By.id("hypothetical"));
hyp.click();
答案 1 :(得分:0)
使用以下代码:
//Click on main menu that will opens the sub Menu list
WebElement ic = driver.findElement(By.id("presentations"));
ic.click();
如果您要求点击每个子菜单项,请使用以下代码: 点击假设:
ic.findElement(By.id("hypothetical")).click();
点击个人资料是:
ic.findElement(By.id("profile")).click();
(Or)
您还可以一次获取所有子菜单项,如下所示:
//Get all the sub menu list.
List<WebElement> list = ic.findElements(By.tagName("a"));
for(int i=0;i < list.size; i++){
WebElement subMenuElement = list.get(i);
subMenuElement.click();
}