微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法在带有 Splash 的 Lua 脚本中单击按钮

如何解决无法在带有 Splash 的 Lua 脚本中单击按钮

这个问题本质上类似 to this question,但在尝试提供的解决方案后,我的问题仍然存在。

我希望我的 Lua 脚本在关闭时对模态弹出窗口做出反应。但是,最终的屏幕截图一直显示模态弹出窗口,因此表明它尚未关闭

这是我想从中抓取的初始链接:'https://www.goodreads.com/search?utf8=%E2%9C%93&query='

这是我的 Lua 脚本:

function main(splash,args)
  splash.private_mode_enabled = false
  splash:set_user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0")
  assert(splash:go(args.url))
  assert(splash:wait(0.5))

  input_Box = assert(splash:select('#search_query_main'))
  input_Box:focus()
  input_Box:send_text("dostoevsky")
  input_Box:send_keys("<Enter>")
  assert(splash:wait(1)) 

  if not splash:select('div.modal--centered div.modal__close') == nil then
    close_button = splash:select('div.modal--centered div.modal__close > button')
    close_button.style.border = "5px solid black"
    close_button:mouse_click()
  end
  splash:wait(1)

  return {
    num_modal = #splash:select_all('div.modal--centered div.modal__close'),num_close_btns = #splash:select_all('div.modal--centered div.modal__close > button'),html = splash:html(),png = splash:png(),}
end

函数返回 num_close_btns: 1num_modal: 1 从而表明我的 css 选择器很好所以我只能假设 mouse_click 事件没有做我期望它做的事情。

Screenshot of modal popup

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。