点击使用selenium

时间:2017-01-31 14:43:31

标签: java selenium

我想点击HTML代码的子菜单。

<div class="appDiv">
    <div class="hreftheme_AppLinks_sub_links_Li_Megamenu">
        <a onclick="appSubmit('/ultimatixPortalWeb/portlets/applications/redirect.jsp?PARAM=236','236','_blank')" href="#"> Timesheet Entry </a>
        <span id="addTofavImage_236" class="favImage" onclick="" title=""> </span>
    </div>
</div>

我尝试了以下可能性,但没有一个成功

1)

action.moveToElement(driver.findElement(By.className("appDiv"))).build().perform();         
driver.findElement(By.className("hreftheme_AppLinks_sub_links_Li_Megamenu")).click();

2)

action.moveToElement(driver.findElement(By.linkText(Link name))).click().build().perform();
driver.findElement(By.linkText(str)).click();

3)

// JavascriptExecutor executor = (JavascriptExecutor)driver;
         //executor.executeScript("arguments[0].click();", webelement for link );

4)

driver.findElement(By.xpath(".//*[@id='parentGroup_26']/div[1]/table/tbody/tr/td[1]/div/div[12]/div/a")).click();

并且还有绝对的xpath,但没有一个能够解决。

1 个答案:

答案 0 :(得分:0)

Actions actions = new Actions(driver); 
WebElement menuHoverLink = driver.findElement(By.linkText("My Sub Menu"));
actions.moveToElement(menuHoverLink).perform();
driver.findElement(By.cssSelector("My Sub Menu Item")).click();