t.me/atinfo_chat Telegram группа по автоматизации тестирования

Can not click on a link without href attribute using WebDriver

Теги: #<Tag:0x00007f748a76ab28> #<Tag:0x00007f748a76aa38> #<Tag:0x00007f748a76a8d0> #<Tag:0x00007f748a76a790>

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="http://www.w3.org/2000/svg"><use class="default-icon" xlink:href="/Content/app/images/public/sprite.svg#search-icon-red" xmlns:xlink="http://www.w3.org/1999/xlink"></use><use class="focus-icon hover-icon" xlink:href="/Content/app/images/public/sprite.svg#search-icon-black" xmlns:xlink="http://www.w3.org/1999/xlink"></use></svg>
                    </a>

Try to use Actions.
Or workaround

WebElement element= driver.findElement(By.xpath("//a/svg"));
((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);
1 Симпатия

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