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

clipboard.png

以上是 linux环境下selenium+PhantomJS无法正确找到element 的全部内容, 来源链接: utcz.com/a/163709.html

回到顶部