[英]Selenium Python Execute JavaScript click link i get an error. I think my syntax is wrong
I am trying to click a link on our webpage. 我试图单击我们网页上的链接。 The page is built from GWT.
该页面是从GWT构建的。 I am using the JavaScript execute in Selenium Python.
我正在Selenium Python中使用JavaScript执行。
self.driver.execute_script("document.gElementById('tab_administration').click()")
I get the following error when i run my code: 运行代码时出现以下错误:
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
My code snippet is: 我的代码段是:
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)
Is my JavaScript call syntax incorrect? 我的JavaScript调用语法不正确吗? Why is it failing?
为什么会失败?
In Firefox dev tools it works. 在Firefox开发工具中,它可以工作。 From the console window i enter this line of code:
在控制台窗口中,输入以下代码行:
document.gElementById('tab_administration').click()";
I am trying driver.execute_script because when i try WebDriverWait(self.driver, 10) i get a TimeOut Exception. 我正在尝试使用driver.execute_script,因为当我尝试使用WebDriverWait(self.driver,10)时,我遇到了超时异常。
Some help appreciated. 一些帮助表示赞赏。 Thanks.
谢谢。
Riaz 里亚兹
尝试这个:
self.driver.execute_script("arguments[0].click()", yourElement);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.