Andy Tilston
Andy Tilston

Reputation: 227

href locator not working in Selenium for only one element

I have been writing some selenium scripts whereby I am selecting some options from a drop down list. When I hover over the parent list, it displays a list of children from where I can select an option. This functionality has been working fine for numerous elements, but I have one which is resulting in a 'ElementNotVisibleException'.

I've attached 2 examples of the code I have been using. The top method is working, but the 2nd one I am experiencing issues with. If anyone can help as to why I might be getting this error I would appreciate it.

WORKS

    public static void creditNoteReportFocus(InternetExplorerDriver driver)
{
    driver.findElement(By.xpath("//a[contains(@href, 'CreditNoteReport')]")).sendKeys(Keys.ENTER);
}

DOESN'T WORK

public static void earlySettlementWorkflowFocus(InternetExplorerDriver driver) throws InterruptedException
{
    driver.findElement(By.xpath("//a[contains(@href, 'EarlySettlementMatch?StartUpView=0')]")).sendKeys(Keys.ENTER);
}

SCREENSHOT enter image description here

CODE SNIPPET OF 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>

Upvotes: 1

Views: 375

Answers (1)

Andy Tilston
Andy Tilston

Reputation: 227

I have had to use absolute xpath in order to resolve this.

Upvotes: 1

Related Questions