Javascriptexception «Циклическое значение объекта» с Python selenium actionchains после входа в системуJavascript

Форум по Javascript
Ответить
Anonymous
 Javascriptexception «Циклическое значение объекта» с Python selenium actionchains после входа в систему

Сообщение Anonymous »

Прямое использование ActionChains дает мне «JavascripTexception: сообщение: Циклическое значение объекта». Это только начало происходить сегодня и не давал мне проблем на прошлой неделе, поэтому я очень запутался. Я использую Python 3 в ноутбуке Jupyter. < /P>
код: < /p>
# Open each link in a new tab
for elem in elems:
ActionChains(driver) \
.key_down(Keys.CONTROL) \
.click(elem) \
.key_up(Keys.CONTROL) \
.perform()

< /code>
Существует функция входа в систему, которая подписана до этого, которая также использует тот же драйвер, и Actionchains перестает работать только тогда, когда она вызывает вниз по течению от этой функции входа. Функция входа в систему: < /p>
def login(driver, username, password):
driver.implicitly_wait(5)
driver.get("http://mywebsite.com")
elem = driver.find_element(By.ID, "Username")
elem.clear()
elem.send_keys(username)
elem = driver.find_element(By.ID, "Password")
elem.clear()
elem.send_keys(password)

elem.send_keys(Keys.RETURN)

# Click on link for next section
link = driver.find_element(By.ID, "NextSection")
link.send_keys(Keys.RETURN)

return
< /code>
Мой тестовый код: < /p>
import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()

driver.get('http://google.com')
element = driver.find_element(By.LINK_TEXT, 'Terms')

for x in range(1,5):
ActionChains(driver) \
.key_down(Keys.CONTROL) \
.click(element) \
.key_up(Keys.CONTROL) \
.perform()
print("Upstream of login ActionChains successful")

login(driver)

element2 = driver.find_element(By.LINK_TEXT, 'About')

ActionChains(driver) \
.key_down(Keys.CONTROL) \
.click(element2) \
.key_up(Keys.CONTROL) \
.perform()
print("Downstream of login ActionChains successful")

driver.quit()
< /code>
Что я ожидал: < /p>
Upstream of login ActionChains successful
Downstream of login ActionChains successful
< /code>
Что я получаю: < /p>
Upstream of login ActionChains successful

---------------------------------------------------------------------------
JavascriptException Traceback (most recent call last)
Cell In[41], line 29
21 login(driver)
23 element2 = driver.find_element(By.LINK_TEXT, 'About')
25 ActionChains(driver) \
26 .key_down(Keys.CONTROL) \
27 .click(element2) \
28 .key_up(Keys.CONTROL) \
---> 29 .perform()
30 print("Downstream of login ActionChains successful")
32 driver.quit()

File ~\AppData\Local\anaconda3\Lib\site-packages\selenium\webdriver\common\action_chains.py:94, in ActionChains.perform(self)
92 def perform(self) -> None:
93 """Performs all stored actions."""
---> 94 self.w3c_actions.perform()

File ~\AppData\Local\anaconda3\Lib\site-packages\selenium\webdriver\common\actions\action_builder.py:96, in ActionBuilder.perform(self)
94 enc["actions"].append(encoded)
95 device.actions = []
---> 96 self.driver.execute(Command.W3C_ACTIONS, enc)

File ~\AppData\Local\anaconda3\Lib\site-packages\selenium\webdriver\remote\webdriver.py:384, in WebDriver.execute(self, driver_command, params)
382 response = self.command_executor.execute(driver_command, params)
383 if response:
--> 384 self.error_handler.check_response(response)
385 response["value"] = self._unwrap_value(response.get("value", None))
386 return response

File ~\AppData\Local\anaconda3\Lib\site-packages\selenium\webdriver\remote\errorhandler.py:232, in ErrorHandler.check_response(self, response)
230 alert_text = value["alert"].get("text")
231 raise exception_class(message, screen, stacktrace, alert_text) # type: ignore[call-arg] # mypy is not smart enough here
--> 232 raise exception_class(message, screen, stacktrace)

JavascriptException: Message: Cyclic object value
Stacktrace:
RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8
WebDriverError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:197:5
JavaScriptError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:476:5
cloneObject@chrome://remote/content/marionette/json.sys.mjs:46:11
cloneJSON@chrome://remote/content/marionette/json.sys.mjs:207:12
cloneObject@chrome://remote/content/marionette/json.sys.mjs:59:24
cloneJSON@chrome://remote/content/marionette/json.sys.mjs:207:12
cloneObject@chrome://remote/content/marionette/json.sys.mjs:59:24
cloneJSON@chrome://remote/content/marionette/json.sys.mjs:207:12
cloneObject@chrome://remote/content/marionette/json.sys.mjs:59:24
cloneJSON@chrome://remote/content/marionette/json.sys.mjs:207:12
json.clone@chrome://remote/content/marionette/json.sys.mjs:212:22
receiveMessage@chrome://remote/content/marionette/actors/MarionetteCommandsChild.sys.mjs:306:19
< /code>
Почему это происходит? Помощь очень ценится.

Подробнее здесь: https://stackoverflow.com/questions/794 ... hains-afte
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Javascript»