How can I use jQuery with selenium execute_script method?

后端 未结 2 574
醉酒成梦
醉酒成梦 2020-12-22 06:12

How can I use jQuery with the selenium execute_script method, if the current page isn\'t already using jQuery?

For example:

from seleniu         


        
2条回答
  •  萌比男神i
    2020-12-22 07:03

    It seems way better to load a local jquery:

    with open('jquery.js', errors='ignore') as f:
      driver.execute_script(f.read())
    
    title = driver.execute_script('return $("title").text()')
    

    It's faster and you don't have to worry about timing issues.

提交回复
热议问题