2015-08-18 50 views
0

我想點擊我們網頁上的鏈接。該頁面是從GWT構建的。 我在Selenium Python中使用JavaScript執行。Selenium Python執行JavaScript點擊鏈接我得到一個錯誤。我認爲我的語法錯了

self.driver.execute_script("document.gElementById('tab_administration').click()") 

我收到以下錯誤,當我運行我的代碼:

File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 181, in check_response 
raise exception_class(message, screen, stacktrace) 
WebDriverException: Message: JavaScript error 

我的代碼片斷是:

 def click_administration(self): 
     time.sleep(10) 
     #self.driver.find_element(By.ID, 'tab_administration').click() 
     self.driver.execute_script("document.gElementById('tab_administration').click()") 
     #wait = WebDriverWait(self.driver, 10) 
     #element = wait.until(EC.element_to_be_clickable((By.ID, 'tab_administration'))) 
     #element.click() 
     return AdministrationPage(self.driver) 

是我的JavaScript調用語法不正確的?爲什麼失敗?

在Firefox開發工具中它可以工作。從控制檯窗口我進入這行代碼:

document.gElementById('tab_administration').click()"; 

我想driver.execute_script因爲當我嘗試WebDriverWait(self.driver,10)我得到一個超時異常。

有些幫助讚賞。謝謝。

里亞茲

回答

1

試試這個:

self.driver.execute_script("arguments[0].click()", yourElement); 
+0

這是輝煌的,它的工作原理。管理員標籤被點擊。謝謝。 –

+0

這是我使用的代碼。 admin_tab = self.driver.find_element(By.ID,'tab_administration') self.driver.execute_script(「arguments [0] .click()」,admin_tab) –

+0

不客氣,很高興幫助! –

相關問題