Protractor: Click on SVG element not work

孤者浪人 提交于 2019-12-21 23:18:13

问题


I am testing an angularjs App using protractor.

I need to test the click on an SVG element.

Protractor can find the element, it can run the click on the element, but after the click nothing happens.

It should change page after the click.

The code is

el=element(by.xpath('(//*[local-name()="g" ]//*[local-name() = "rect"])[1]'))
    browser.actions().mouseMove(el.getWebElement()).click().perform();

回答1:


I agree with what @alecxe suggested in his comment. You should be calling click() on the element itself:

var el = element(by.xpath('(//*[local-name()="g" ]//*[local-name() = "rect"])[1]'));
el.click();



回答2:


This is still an issue. According to github issues browser.actions() should be used. Following solution finally worked out for me:

await browser.driver.actions().mouseMove(element(by.css('YOUR_LOCATOR')).getWebElement()).perform();
await browser.actions().click().perform();

https://github.com/angular/protractor/issues/2272

https://github.com/angular/protractor/issues/4495



来源:https://stackoverflow.com/questions/30940736/protractor-click-on-svg-element-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!