本文介紹了Selenium 中的 execute_script() 有什么作用的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
browser.execute_script("window.open('about:blank', 'tab2');")
browser.switch_to.window("tab2")
browser.get('http://bing.com')
我在網上搜索在python中使用selenium打開新標簽的方法,ctrl + t的方法不起作用在 chrome 上,所以我偶然發現了上面的代碼,但是我無法理解 'excute_script' 的作用.
I was searching online ways to open a new tab using selenium in python, and the method of ctrl + t wasn't working on chrome so I stumbled on the above piece of code, however I am not able to understand what 'excute_script' does.
推薦答案
execute_script
方法允許執行作為字符串參數傳遞的 JavaScript
execute_script
method allows to execute JavaScript passed as string argument
請注意,您可以使用 arguments
將數據從 Python 代碼傳遞到 JavaScript 代碼,例如
Note that you can pass data from Python code into JavaScript code using arguments
, e.g.
hello = "Hello"
friends = " friends"
browser.execute_script('alert(arguments[0], arguments[1]);', (hello, friends))
這篇關于Selenium 中的 execute_script() 有什么作用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!