href locator not working in Selenium for only one element

Answered

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. I’ve highlighted in bold the Xpath I am using

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);
}

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>

tilston1001 Train Asked on December 3, 2014 in Selenium WebDriver.
Add Comment
1 Answer(s)
Best answer

Hi Andy,

The href value looks messy to me and it seems like it is generating dynamically and contain special characters. Avoid using it.

User the Linktext method  ‘Early Settlement Workflow’ to identify your element.

Always paste the front end screen shot as well, it helps us to understand the problem.

Regards,
Lakshay Sharma

xLov3rDns Professor Answered on December 8, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.