Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

Selenium 2 Python webdriver:

I was trying to click on an element which is hidden due to the hover effect and was looking for options to unhide and be able to select the element. To do this, I referred to some examples like below:

In java:

JavascriptExecutor je = (JavascriptExecutor) webDriver();

Another example:

browser.execute_script("document.getElementsByClassName('classname').style.display='block'")

When I ran the above example, I got the following exception:

selenium.common.exceptions.WebDriverException: Message: '' 

I am not sure if I had to include any class for executing the javascript. Please let me know if there is anything iam missing.

share|improve this question
    
Try to get the actual javascript which that element(which you want to click) runs and then execute it using browser.execute_script. For that you can use something like FireBug. – theharshest Feb 16 '12 at 11:44
up vote 2 down vote accepted

That is because getElementsByClassName returns array of DOM elements. If you need to access first one change your JS to document.getElementsByClassName('classname')[0].style.display='block'

share|improve this answer
    
Thanks for ur reply. It worked fine now – user1207929 Feb 16 '12 at 18:53

I am using below command in python to click on an element which is hidden

element=driver.find_element_by_xpath("//div[2]/div/div[2]/div[1]") driver.execute_script("arguments[0].click();", element)

share|improve this answer
    
What is arguments here? – Volatil3 Jul 28 '16 at 8:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.