简体   繁体   English

Selenium Python执行JavaScript单击链接,我得到一个错误。 我认为我的语法是错误的

[英]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.

相关问题 JavaScript语法错误(我认为) - JavaScript syntax error (I think) Javascript错误......我想 - Javascript error… I think 我无法完全加载PHP / XHTML页面。 我认为这是语法错误,但我找不到它 - I cannot get my PHP/XHTML page to fully load. I think it is a syntax error but I cannot find it 如何通过将链接与用户输入文本进行匹配来让 Python 和 Selenium 单击 angularjs 链接? - How do I get Python and Selenium to click an angularjs link by matching the link to user input text? 我认为已定义的JavaScript代码中出现“未定义”错误 - Getting a “not defined” error in my JavaScript code when I think it is defined 如何将我的 javascript 文件与 html 链接? 我认为我已正确链接但无法正常工作? - how can i link my javascript file with html???? I think i have linked properly but not working? 如何在Python Selenium中执行JavaScript代码,然后在我的Python代码中调用它? - How do i execute JavaScript code in Python Selenium and then call it back in my Python code? Javascript void(0)单击或使用Selenium Python执行 - Javascript void(0) click or execute using selenium python 如何使用 selenium 在 python 中执行 JavaScript 代码? - How do I execute a JavaScript code in python using selenium? 我如何执行javascript以使用python和selenium更改日期 - How can I execute javascript to change a date with python and selenium
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM