How to execute a Javascript function in python with selenium

前端 未结 2 2046
花落未央
花落未央 2020-12-08 23:15

I have a function called \'checkdata(code)\' in javascript, which, as you can see, takes an argument called \'code\' to run and returns a 15-char string.

So, I found

相关标签:
2条回答
  • 2020-12-08 23:38

    Build the string

    a = wd.execute_script("return checkdata('" + code + "');")
    
    0 讨论(0)
  • 2020-12-08 23:55

    Rather than building a string (which means you'd have to escape your quotes properly), try this:

    a = wd.execute_script("return checkdata(arguments[0])", code)
    
    0 讨论(0)
提交回复
热议问题