0

I am trying to click a link on our webpage. The page is built from GWT. I am using the JavaScript execute in Selenium Python.

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? Why is it failing?

In Firefox dev tools it works. 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.

Some help appreciated. Thanks.

Riaz

1 Answer 1

2

try this:

self.driver.execute_script("arguments[0].click()", yourElement);
Sign up to request clarification or add additional context in comments.

2 Comments

That's brilliant, it works. The admin tab was clicked. Thanks.
This is the code i used. admin_tab = self.driver.find_element(By.ID, 'tab_administration') self.driver.execute_script("arguments[0].click()", admin_tab)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.