使用selenium webdriver测试上下文菜单的显示

时间:2014-09-03 12:44:40

标签: html selenium junit selenium-webdriver automated-tests

当我在组件中单击鼠标右键时,我有一个测试contxxt菜单显示的问题

这是我的代码HTML

<div contextmenu="menuContext" class="demo" id="global" style="display:block;"> 
    I do something ...          
</div>
<menu type="context" id="menuContext">                       
    <menuitem id="abc" label="label1" onclick="window.location='page1.html';"></menuitem>
    <menuitem id="def" label="label2" onclick="window.location='page1.html';"></menuitem>
    <menuitem id="ghi" label="label3" onclick="window.location='page3.html';"></menuitem>
    <menuitem id="jkl" label="label4" onclick="window.location='page1.html';"></menuitem>
    <menuitem id="mno" label="label5" onclick="window.location='page2.html';"></menuitem>
</menu>

这是我的硒测试代码:

private void verifyComponent(final String myId) {
    final WebElement component = this.driver.findElement(By.id(myId));
    final boolean testComponent = component.isDisplayed();
    assertTrue("verification of compnent: ", testComponent);
}

private void verifyMCappearance() {
    final List<WebElement> elementNumList =
            this.driver.findElements(By.id("global"));
    // Taking 1st cell
    final WebElement link = elementNumList.get(0);
    // Right Clicking
    new Actions(this.driver).contextClick(link).perform();
    verifyComponent("menuContext");
}
//call method
verifyMCappearence();

所以我的网页显示是正确的,右键单击工作,我看到上下文菜单。但我不知道为什么我不能用断言方法测试它! 当我在firebug中看到我的代码html,即使我右键单击或不是我总是隐藏上下文菜单的代码html可能是问题。

请帮忙!

0 个答案:

没有答案
相关问题