如何使用selenium java访问动态td值

时间:2015-03-04 13:54:45

标签: java html selenium xpath

以下是我的HTML代码

<td class="MenuEntryName" nowrap="">Business Insurance</td>`

当鼠标悬停在它上面时,std代码变为

<td class="MenuEntryNameHover" nowrap="">Business Insurance</td>

我已经尝试过使用动作类

WebElement SelectBusinessInsurance1 = driver.findElement(By.xpath("//td[contains(@class, 'MenuEntryName') and text()='Business Insurance']"));
    Actions action = new Actions(driver);
    WebElement mainMenu = driver.findElement(By.xpath("//td[contains(@class, 'MenuEntryNameHover') and text()='Business Insurance']"));
    action.moveToElement(mainMenu).moveToElement(SelectBusinessInsurance1).click().build().perform();

1 个答案:

答案 0 :(得分:0)

也许下面的Xpath可以帮助你

//td[contains(@class, 'MenuEntryName') and contains(text(), 'Business Insurance')]

如果类是menuEntry或menuEntryName

,它应该得到td无关紧要