The findElement example you provided should have worked. I'm assuming
it fails to find the element. If this is not true or you aren't sure
you might want to break the code into two lines, i.e.
WebElement anchor = driver.findElement(By.xpath("//a[contains(@href,'/
ccc/ctxxxx/Load.xxx?ID')]"));
anchor.click();
If it fails on the second line then you know the problem is not
finding the element but clicking it.
If it fails to find the element, the only thing I can guess is that
whatever WebDriver sees is not the same as what you think it sees.
Occasionally, the tools we use to examine a web page don't show us
exactly the same as what WebDriver sees. In these cases I'll write a
little snippet which will find what I'm looking for and examine it.
For example,
List<WebElement> anchors = driver.findElements(By.tagName("a"));
After this line of code I'd set a breakpoint and run to breakpoint.
Once halted at the breakpoint I can use the watch window to examine
the contents of 'anchors'. I put anchors.size() in the watch window
then I examine anchors.get(n).getAttribute("href") where n is from 0
to anchors.size()-1. Alternatively, I could just write the program:
List<WebElement> anchors = driver.findElements(By.tagName("a"));
Iterator<WebElement> i = anchors.iterator();
while(i.hasNext()) {
WebElement anchor = i.next();
String href = anchor.getAttribute("href");
System.out.println(href);
}
From the output of this I might see why my assumptions about the href
attribute are wrong. Could the findElement match more than one
WebElement? Not sure what would happen there.
Darrell
P.S. you might also want to use
driver.findElement(By.cssSelector("a[href*='/ccc/ctxxxx/Load.xxx?
ID'")); rather than an xpath. This is more writing efficient code and
nothing to do with your actual problem.