Can not click on a link without href attribute using WebDriver

Is it possible to click on a link somehow using WebDriver , if it does not contain “href” attribute? Webdriver’s found it successfully, but cannot click.

Manual click requests to javascript (script listens some event and then opens target page)

<a role="button" class="search-btn">
                        <svg class="inline-icon search-icon-red" onmouseup="svgClickPolyfill.apply(this, arguments)" xmlns=""><use class="default-icon" xlink:href="/Content/app/images/public/sprite.svg#search-icon-red" xmlns:xlink=""></use><use class="focus-icon hover-icon" xlink:href="/Content/app/images/public/sprite.svg#search-icon-black" xmlns:xlink=""></use></svg>

Try to use Actions.
Or workaround

WebElement element= driver.findElement(By.xpath("//a/svg"));
((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);
1 Like

не будет так работать, попробуй другой локатор
WebElement element= driver.findElement(By.xpath("//a/*[local-name()=‘svg’]"));