2011-03-09 24 views
3

以下的硒-1正常工作:
什麼是get_eval相當於硒webdriver的Python中

sel = self.selenium 
sel.get_eval("window.$('body form div ul li').html()") 

當我嘗試在同一Python中硒webdriver的2,我得到一個錯誤。

wd = webdriver.Firefox() 
wd.execute_script("window.$('body form div ul li').html()") 

selenium.webdriver.common.exceptions.WebDriverException: window.$ is not a function 

如何讓jquery在python中的webdriver中工作?

+4

能夠解決這個問題。我錯過了execute_script中的返回。 wd.execute_script(「return window。$('body form div ul li')。html()」) – user652124 2011-03-10 00:48:25

+0

回答你自己的問題並接受它是可以的。如果你這樣做,找到正確的答案會更容易。 – 2011-10-01 16:34:15

回答

4

在selenium1中get_eval()計算腳本並返回結果。

當你使用execute_script()時,你必須顯式地返回你感興趣的值。

相關問題