简体   繁体   English

如何将浏览器脚本中返回的变量解析为 Python 代码?

[英]How to parse variables returned in browser script to Python code?

I am runnning the following script in the browser我在浏览器中运行以下脚本

webdriver.execute_script("document.getElementsByClassName('bulk_item').length")

and I want the number this script returns to be assigned to an elem variable that I can access.我希望将此脚本返回的数字分配给我可以访问的elem变量。 Direct assignment doesn't work.直接分配不起作用。 The error is on line:错误在线:

self.assertEqual(elem_before+1, elem_after, "UPLOAD FAILED")

TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

Add a return statement.添加return语句。

webdriver.execute_script("return document.getElementsByClassName('bulk_item').length")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM