arsenic icon indicating copy to clipboard operation
arsenic copied to clipboard

Object of type 'CompatElement' is not JSON serializable

Open largomath2010 opened this issue 6 years ago • 2 comments

Hi,

I'm trying to use execute script and passing element to the script. The document is not so clear about this except: Arguments to pass to the script. Must be JSON serializable.

So I try:

button = await session.get_element(button_css)
scroll_script = "button.scrollIntoView(false)"
await session.execute_script(scroll_script, {'button': button})

But it turn out Object of type 'CompatElement' is not JSON serializable.

What is correct way to do this?

largomath2010 avatar Feb 13 '19 05:02 largomath2010

You should get the button in javascript itself, so something like execute_script("document.querySelector(arguments[0]).scrollIntoView(false)", button_css) should work.

ojii avatar Feb 13 '19 05:02 ojii

So, I loop through a list of element from get_elements() and do some same process for all of them.

That's why i can not pass the button_css.

Is there anyway i can extract the css/xpath selector of current selected element and pass it to execute_scripts ?

largomath2010 avatar Feb 13 '19 05:02 largomath2010