[英]Selenium Python Execute JavaScript click link i get an error. I think my syntax is wrong
我試圖單擊我們網頁上的鏈接。 該頁面是從GWT構建的。 我正在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)時,我遇到了超時異常。
一些幫助表示贊賞。 謝謝。
里亞茲
嘗試這個:
self.driver.execute_script("arguments[0].click()", yourElement);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.