【问题标题】:When I used function click on the chrome console I get undefined当我使用功能单击 chrome 控制台时,我得到未定义
【发布时间】:2018-04-27 14:49:33
【问题描述】:

我正在使用 xpath 尝试单击,但未定义。

$x('//*[@id="form-container"]/ul/li[8]/div/div[2]/a')[0].click();

您可以手动点击有没有其他方法可以点击控制台,我尝试了$x('//*[@id="form-container"]/ul/li[8]/div/div[2]/a').click()但不起作用。

【问题讨论】:

  • 是未定义的意思是方法上没有javascript?

标签: javascript jquery google-chrome xpath


【解决方案1】:

你可以在一个html元素上创建一个点击eventdispatch

var evt = new Event("click", {"bubbles":true});
document.addEventListener("click",e=>console.log("clicked",e));
document.dispatchEvent(evt);

【讨论】:

  • 我创建了事件并运行命令,这是我得到的:clicked MouseEvent {isTrusted: false, satellite: 35, screenX: 0, screenY: 0, clientX : 0, ...}
  • 如果我手动单击并得到以下信息:单击 MouseEvent {isTrusted: true, satellite: 29, screenX: 2189, screenY: 244, clientX: 909, ...}
  • @RafaSotoChan 你期待什么?
  • $x('//*[@id="form-container"]/ul/li[8]/div/div[2]/a/span[2]')[0 ]。点击();如果我运行应该显示选项的命令,例如当您单击按钮时会发生其他事情,那么两者应该具有相同的结果
  • @RafaSotoChan 你试过了吗$x('//*[@id="form-container"]/ul/li[8]/div/div[2]/a/span[2]')[0].dispatchEvent(new Event("click", {"bubbles":true}));
猜你喜欢
  • 2014-10-13
  • 1970-01-01
  • 2021-09-15
  • 2017-06-23
  • 2020-11-16
  • 2012-02-21
  • 2021-12-20
  • 2018-12-10
  • 1970-01-01
相关资源
最近更新 更多