LoginSignup
0
0

More than 5 years have passed since last update.

phantomJSで'Element is not currently visible and may not be manipulated'エラーが出る

Posted at

環境

CentOS Linux release 7.4.1708 (Core)
python 3.4.3
phantomjs 2.1.1
selenium 3.5.0

code

driver = webdriver.PhantomJS(service_log_path=os.path.devnull)
driver.get(some_url)
buttons = driver.find_elements_by_css_selector(some_css_selector)
for button in buttons:
    button.click()

症状

click()のタイミングでこんなのが出てくる。

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":"xxx.xxx.xxx.xxx:xxxxx","User-Agent":"Python http auth"},"httpVersion":"1.1","method":"POST","post":"{\"id\": \":wdc:1511762011951\", \"sessionId\": \"4ba89190-d337-11e7-819f-c929cfc19434\"}","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/4ba89190-d337-11e7-819f-c929cfc19434/element/:wdc:1511762011951/click"}}
Screenshot: available via screen

対症療法

ブラウザサイズを指定する

driver = webdriver.PhantomJS(service_log_path=os.path.devnull)
driver.set_window_size(1350, 640)  # <---- ここ
driver.get(some_url)
buttons = driver.find_elements_by_css_selector(some_css_selector)
for button in buttons:
    button.click()

結果

エラーが起こらなくなった。
めでたしめでたし。

参考URL

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0