1

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>
Andy Tilston
  • 227
  • 1
  • 5
  • 18
  • Please provide a HTML snippet that shows the element(s) in question so we can help you out, thanks. – Mark Rowlands Dec 03 '14 at 16:35
  • Hi Mark, details are now attached. Thanks – Andy Tilston Dec 03 '14 at 16:44
  • Screenshots are **useless** for showing code! In your second XPath, what are the asterisks **outside** of the single-quotations suppose to be? – SiKing Dec 03 '14 at 16:45
  • Simon, please no longer comment on my questions as I am fed up of your sarcastic and condescending responses. many thanks – Andy Tilston Dec 03 '14 at 16:47
  • Wonder if the question mark symbol is throwing off the XPath. Have you tried using different text in the contains to see if the element is being found? As an example `By.xpath("//a[contains(@href, 'EarlySettlementMatch')]")` – shri046 Dec 03 '14 at 17:19
  • Hi Shri, thanks for the response. It's very odd, even when I remove the question mark I still get the error......but, again, only on this element – Andy Tilston Dec 03 '14 at 17:24
  • 1
    Oh the exception stems from the element not being visible. For some reason I thought it was element not found exception. It is possible that the code executes before the element becomes visible in case of dynamic nature of the menu. Try adding a wait for visibility as mentioned in [this post](http://stackoverflow.com/questions/10941184/equivalent-of-waitforvisible-waitforelementpresent-in-selenium-webdriver-tests-u). – shri046 Dec 03 '14 at 18:14
  • There is some way to make that element visible. Selenium will not perform any action on the element that is not visible. I can pretty much tell your item is not visible so use some `wait` for the element to be visible – Saifur Dec 03 '14 at 18:17
  • Hi, thanks for both of your comments. I've now added a webdriver wait and applied a time limit of 30 seconds, but after this time the element is not visible. The one thing that is different on this element, compared to ones that have previously worked is that it has a '?' in it, as follows 'EarlySettlementMatch?StartUpView=0' – Andy Tilston Dec 04 '14 at 09:21

1 Answers1

1

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

Andy Tilston
  • 227
  • 1
  • 5
  • 18