HENNGE / arsenic

Async WebDriver implementation for asyncio and asyncio-compatible frameworks
Other
350 stars 53 forks source link

Object of type 'CompatElement' is not JSON serializable #59

Open largomath2010 opened 5 years ago

largomath2010 commented 5 years ago

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?

ojii commented 5 years ago

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

largomath2010 commented 5 years ago

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 ?