Manan Sharma
Manan Sharma

Reputation: 571

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. 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'

Upvotes: 0

Views: 64

Answers (1)

cuspymd
cuspymd

Reputation: 1088

Add a return statement.

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

Upvotes: 1

Related Questions