python selenium phantomjs execute_script - PullRequest
       22

python selenium phantomjs execute_script

0 голосов
/ 16 декабря 2018

Почему возникает ошибка при использовании phantomjs?

from selenium import webdriver
page_index = 1076
#driver = webdriver.Chrome() # no any errors.
driver = webdriver.PhantomJS() # will error.    
driver.get('https://www.nexusmods.com/mods/')    
driver.execute_script(f"window.RH_ModList.Send('page', '{page_index}');")

Результат:

raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: {"errorMessage":"undefined is not an object (evaluating 'window.RH_ModList.Send')","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"118","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:57491","User-Agent":"Python http auth"},"httpVersion":"1.1","method":"POST","post":"{\"script\": \"window.RH_ModList.Send('page', '1076');\", \"args\": [], \"sessionId\": \"e7abf670-0132-11e9-ba9e-f19731f1c19f\"}","url":"/execute","urlParsed":{"anchor":"","query":"","file":"execute","directory":"/","path":"/execute","relative":"/execute","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/execute","queryKey":{},"chunks":["execute"]},"urlOriginal":"/session/e7abf670-0132-11e9-ba9e-f19731f1c19f/execute"}}
Screenshot: available via screen

1 Ответ

0 голосов
/ 16 декабря 2018

Почему возникает ошибка при использовании phantomjs?

Это потому, что PhantomJS не поддерживает ES6 Promise См. Проблему в Github здесь .если вы выполните отладку, вы увидите эту ошибку для этой страницы

ReferenceError: Невозможно найти переменную: Promise

phantomjs: //platform/bootstrap.js: 87 2

ReferenceError: Невозможно найти переменную: $

Поскольку отказ от PhantomJS не может быть легко исправить.

...