无法在量角器中单击元素

时间:2018-05-28 13:02:50

标签: protractor

我正在尝试单击span中的元素但不成功。这是我的代码。

尝试1:

browser.executeScript('arguments[0].scrollIntoView();', elem.getWebElement());

尝试2:

elm.click();

尝试3:

  <button class="button tooltip-bottom ng-star-inserted" data-gs-tooltip=“this will display tooltip“>
      <span class="button-icon"><img class="button-icon" src="sample/pics/icnsvg"></span>
     <div class="button-label">show good</div>
</button>

尝试4:

双击。

当我使用上述任何一种方法时,我看到鼠标悬停在按钮上,并显示工具提示文本。但是没有点击该元素。

这是我的应用程序代码:

let lat =  "33.847105"
let long = "-118.2673272"
let region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: Double(lat)!, longitude: Double(long)!), span: MKCoordinateSpan(latitudeDelta: 0.95, longitudeDelta: 0.95))
DispatchQueue.main.async {
    self.mapView(self.mapView, regionDidChangeAnimated: true)
}

我正在努力完成这项工作。任何建议表示赞赏。

谢谢:)

3 个答案:

答案 0 :(得分:1)

Protractor API是异步的。您需要使用promise对象来处理它。 你需要在这里解决这个承诺。因此,即使在页面准备好之前也不应执行按钮单击。

检查此代码:

function openURL(url) {
  var link = document.createElement('a');
  link.target = "_blank";
  link.href = url;
  link.rel = "noopener noreferrer";
  document.body.appendChild(link); // you need to add it to the DOM to get FF working
  link.click();
  link.parentNode.removeChild(link); // link.remove(); doesn't work on IE11
};

它应该工作。如果您需要更多帮助,请告诉我。

答案 1 :(得分:0)

试试这个

var elem = element(by.css('.button span'));
return browser.actions().mouseMove(elem).click().perform();

答案 2 :(得分:0)

我修好了。我添加了

 browser.sleep(10000)

点击按钮之前。

令我惊讶的是我使用过

browser.wait(protractor.ExpectedConditions.elementToBeClickable

仍然无法让它发挥作用。睡眠声明有帮助。

谢谢你。

相关问题