Python+Selenium在webpag上提交查询

2024-10-02 04:35:09 发布

您现在位置:Python中文网/ 问答频道 /正文

大家好…我正在尝试使用Python和Selenium提交查询,Google地图上的一对坐标“40.67243,-74.08379”。在

driver = webdriver.PhantomJS()
driver.get('https://maps.google.com/')
driver.find_element_by_id("searchboxinput").clear()
driver.find_element_by_id("searchboxinput").send_keys("40.67243, -74.08379")
driver.find_element_by_css_selector("button.searchbutton").click()

使用上述命令将返回错误消息块,问题从以下位置开始:

^{pr2}$

当我从Chrome上检查它时,似乎没有元素“searchboxinput”。这是原因吗?在

如何提交查询?谢谢。在

错误:

Traceback (most recent call last):
  File "C:\Python27\Gmap.py", line 10, in <module>
    driver.find_element_by_id("searchboxinput").clear()
  File "C:\Python27\lib\selenium\webdriver\remote\webdriver.py", line 197, in find_element_by_id
    return self.find_element(by=By.ID, value=id_)
  File "C:\Python27\lib\selenium\webdriver\remote\webdriver.py", line 681, in find_element
    {'using': by, 'value': value})['value']
  File "C:\Python27\lib\selenium\webdriver\remote\webdriver.py", line 164, in execute
    self.error_handler.check_response(response)
  File "C:\Python27\lib\selenium\webdriver\remote\errorhandler.py", line 164, in check_response
    raise exception_class(message, screen, stacktrace)
NoSuchElementException: Message: u'{"errorMessage":"Unable to find element with id \'searchboxinput\'","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"95","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:62738","User-Agent":"Python-urllib/2.7"},"httpVersion":"1.1","method":"POST","post":"{\\"using\\": \\"id\\", \\"sessionId\\": \\"e6a0af20-4f91-11e4-a8b7-7b4551650c5b\\", \\"value\\": \\"searchboxinput\\"}","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/e6a0af20-4f91-11e4-a8b7-7b4551650c5b/element"}}' ; Screenshot: available via screen 

Tags: inpyidbyvaluelibdriverselenium

热门问题