linux环境下selenium+PhantomJS无法正确找到element

发布于 2022-09-06 15:13:39 字数 1527 浏览 12 评论 0

环境:python3.5,selenium2.53.1

from selenium import webdriver

def startSpider():
    driver = webdriver.PhantomJS(executable_path='/usr/local/src/phantomjs/bin/phantomjs')
    driver.get('https://www.baidu.com')
    driver.implicitly_wait(9)
    driver.find_element_by_id('kw').clear()
    driver.find_element_by_id('kw').send_keys('kw')
    driver.find_element_by_id('su').click()
    html=driver.page_source
    print(html)

startSpider()

报异常

selenium.common.exceptions.NoSuchElementException: Message: {"errorMessage":"Unable to find element with id 'kw'","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"83","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:41997","User-Agent":"Python-urllib/3.5"},"httpVersion":"1.1","method":"POST","post":"{\"sessionId\": \"af013960-0f30-11e8-b233-5d568888cde5\", \"using\": \"id\", \"value\": \"kw\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/af013960-0f30-11e8-b233-5d568888cde5/element"}}
Screenshot: available via screen

应该无需切frame

clipboard.png

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文