Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
151
rated 0 times [  158] [ 7]  / answers: 1 / hits: 15469  / 13 Years ago, wed, february 15, 2012, 12:00:00

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.


More From » python

 Answers
87

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'


[#87441] Tuesday, February 14, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
antonb

Total Points: 424
Total Questions: 104
Total Answers: 101

Location: Serbia
Member since Tue, Jul 26, 2022
2 Years ago
;