linux环境下selenium+PhantomJS无法正确找到element
环境: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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论