使用Python+selenium获取tag_element标签输入内容出现错误

今天第一次使用Python写脚本,目的:登陆www.zealer.com,在搜索框搜索“小米8”
编辑python代码:

from selenium import webdriver
from time import sleep

driver=webdriver.Chrome()

driver.get("http://www.zealer.com")
#driver.maximize_window()     
driver.find_element_by_tag_name("input").send_keys("小米8")
sleep(3)
driver.quit()

当时没用到是网页窗口最大化显示:driver.maximize_window()
导致结果:
使用Python+selenium获取tag_element标签输入内容出现错误_第1张图片
同时Pycharm开始报错:

"C:\Program Files\Python3\python.exe" E:/python_script/Webdriver/Find_Element/By_tagName.py
Traceback (most recent call last):
  File "E:/python_script/Webdriver/Find_Element/By_tagName.py", line 8, in 
    driver.find_element_by_tag_name("input").send_keys("小米8")
  File "C:\Program Files\Python3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 479, in send_keys
    'value': keys_to_typing(value)})
  File "C:\Program Files\Python3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "C:\Program Files\Python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Program Files\Python3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not interactable
  (Session info: chrome=71.0.3578.80)
  (Driver info: chromedriver=71.0.3578.80 (2ac50e7249fbd55e6f517a28131605c9fb9fe897),platform=Windows NT 10.0.17134 x86_64)


Process finished with exit code 1

反复检查代码,百思不得其解。
最后试一下窗口最大化显示:driver.maximize_window()

代码运行成功。

分析原因:selenium.common.exceptions.ElementNotVisibleException: Message: element not interactable
提示元素不可交互,说明窗口化没有显示到搜索框,代码无法继续运行?

你可能感兴趣的:(selenium)