1. 程式人生 > >selenium 訪問網頁拋出ElementNotVisibleException異常

selenium 訪問網頁拋出ElementNotVisibleException異常

method 描述 app pytho 導致 key rom version win

問題描述:

在使用selenium時遇到如下異常導致程序終止:

selenium.common.exceptions.ElementNotVisibleException: Message: {"errorMessage":"Element is not currently visible and may not be manipulated","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"81","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:55400","User-Agent":"Python http auth"},"httpVersion":"1.1","method":"POST","post":"{\"id\": \":wdc:1507345910060\", \"sessionId\": \"416c7180-ab0d-11e7-b13e-8162184dcb19\"}","url":"/click","urlParsed":{"anchor":"","query":"","file":"click","directory":"/","path":"/click","relative":"/click","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/click","queryKey":{},"chunks":["click"]},"urlOriginal":"/session/416c7180-ab0d-11e7-b13e-8162184dcb19/element/:wdc:1507345910060/click"}}
Screenshot: available via screen

解決辦法:

在啟動對應瀏覽器驅動後,添加如下所示深紫色所示內容。(Note:該條語句用於設置窗口顯示尺寸規格,最好設置為您當前pc的電腦分辨率

brower = webdriver.Chrome()

brower.set_window_size(1920, 1080)

selenium 訪問網頁拋出ElementNotVisibleException異常