I am having trouble clicking on a dynamically generated link that triggers some JavaScript. Despite trying to use various methods such as 'onclick' and JavaScripExecutor, I cannot seem to locate the element on the page. The code snippet I am currently working with is shown below:
<a class="a68a" target="_top" style="cursor:pointer;" href="" onkeypress="if(event.keyCode == 13 || event.which == 13){ClientReportc2b21bbce37e4f5ba98575a2680610a2.ActionHandler('Drillthrough','64iT0R0x0:0');}return false;" onclick="ClientReportc2b21bbce37e4f5ba98575a2680610a2.ActionHandler('Drillthrough','64iT0R0x0:0');return false;" tabindex="1">
<div class="r13" style="WIDTH:17.42mm;">
<div class="a67"> <span class="a66">123456789</span> </div>
</div>
</a>
Despite my efforts, I have not been successful in clicking the link using the approaches outlined below:
(a) driver.findElement(By.linkText("ClientReport8522bb9804044e969553e386b7010c6d.ActionHandler('Drillthrough','64iT0R0x0:0')")).click();
(b) driver.findElement(By.xpath("//a[@onclick='ClientReport8522bb9804044e969553e386b7010c6d.ActionHandler('Drillthrough','64iT0R0x0:0')']")).click();
(c) WebElement element = driver.findElement(By.xpath("//a[@class='a68a']"));
element.click();
(d) WebElement element= driver.findElement(By.xpath("//a[@class='a68a']"));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element);
I suspect that attempts (a) and (b) are unsuccessful because part of the JavaScript name is generated dynamically, making it unreliable. Any assistance in resolving this issue would be greatly appreciated. Thank you.