我一直在编写一些 Selenium 脚本,从中我从下拉列表中选择一些选项。当我将鼠标悬停在父列表上时,它会显示一个子列表,我可以从中选择一个选项。此功能对于许多元素都运行良好,但我有一个导致“ElementNotVisibleException”。
我附上了我一直在使用的代码的 2 个示例。第一种方法有效,但第二种方法我遇到了问题。如果有人可以帮助我解释为什么我可能会收到此错误,我将不胜感激。
有效
public static void creditNoteReportFocus(InternetExplorerDriver driver)
{
driver.findElement(By.xpath("//a[contains(@href, 'CreditNoteReport')]")).sendKeys(Keys.ENTER);
}
不起作用
public static void earlySettlementWorkflowFocus(InternetExplorerDriver driver) throws InterruptedException
{
driver.findElement(By.xpath("//a[contains(@href, 'EarlySettlementMatch?StartUpView=0')]")).sendKeys(Keys.ENTER);
}
屏幕截图
HTML 代码片段
<div class="inner">
<img alt="barney" runat="server" src="/DibsAndrew/images/chinook/gfx-topnav-left.gif"/>
<ul class="drop-down-menu sub-nav">
<li>
<li>
<li>
<li>
<a class="highlighted" href="/DibsAndrew/CCLReports/Overall">Reports</a>
<ul id="ddm-86476" style="display: block;">
<li>
<li>
<a class="highlighted" href="#">Collections</a>
<span>»</span>
<ul style="display: block;">
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<a class="highlighted" href="/DibsAndrew/ETCalculator/EarlySettlementMatch?StartUpView=0">Early Settlement Workflow</a>
</li>
最佳答案
我不得不使用绝对 xpath 来解决这个问题。
关于java - href 定位器在 Selenium 中不适用于仅一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27276625/