1

I have this menu that is Javascript Generated. I already tried to locate this menu using xpath but there is an error 'NoSuchElemetFound'. My goal here is to press the menu generated by javascript or Execute the command of the menu (like you click the menu for real).

The menu is in a div tag that is hidden.

Here is the command called by this javascript menu:

parent.navFrame.gotoURL('url');

Here are my current codes that does not work:

WebElement menu = driver.findElement(By.xpath("html/body/span/div[11]/div/div"));
WebElement parentMenu = driver.findElement(By.xpath("html/body/table/tbody/tr/td[6]/a/img"));
Actions builder = new Actions(driver);
builder.moveToElement(parentMenu).moveToElement(menu).click().build().perform();

and this

        Actions builder = new Actions(driver);
        ((HasInputDevices) driver).getMouse();
        builder.moveToElement(driver.findElement(By.xpath("html/body/table/tbody/tr/td[6]/a/img"))).build().perform();
        driver.findElement(By.xpath("html/body/table/tbody/tr/td[6]/a/img")).isSelected();
        Thread.sleep(1000L);    
        builder.moveToElement(driver.findElement(By.xpath(".//*[@id='menuItem101']"))).build().perform();
        driver.findElement(By.xpath(".//*[@id='menuItem101']")).click();
        Thread.sleep(1000L);

Please Help me. Thanks

4

3 回答 3

3

我已经看到 webdriver 无法输入隐藏字段,因此您也可能无法单击隐藏元素。

如果是这种情况,一个潜在的解决方法是执行 javascript

((IJavaScriptExecutor)driver).ExecuteScript("$('#theDivInQuestion').click()");

上面的示例需要 JQuery,但如果 JQuery 在您的页面上不可用,则可以将其转换为常规 java 脚本

于 2013-07-26T02:43:28.200 回答
0

即使菜单被隐藏,您也可以通过以下代码段单击它。

WebElement we = driver.findElement(By.xpath(xpathtotheELEMENT));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", we); 
于 2013-07-26T09:55:51.917 回答
0

该菜单位于隐藏的 div 标签中。

如果该元素被隐藏,则 WebDriver 无法单击它。

于 2013-07-26T02:38:43.763 回答