Удаленка для jenkins+selenide+selenoid+allure+docker спецов на 2-3 часа в день. 100% remote! Присоединиться к проекту

Can not click on a link without href attribute using WebDriver

locators
click
links
webdriver
Теги: #<Tag:0x00007fedb6c5fde0> #<Tag:0x00007fedb6c5fb38> #<Tag:0x00007fedb6c5f9a8> #<Tag:0x00007fedb6c5f868>

(Julia Bodnar) #1

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>

(Bolatbek) #2

Try to use Actions.
Or workaround

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

(Taras) #3

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