0

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.

1
  • 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. Commented Feb 16, 2012 at 11:44

2 Answers 2

3

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'

Sign up to request clarification or add additional context in comments.

Comments

2

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)

1 Comment

What is arguments here?

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.