14

I have a web application which I am automating using WebDriver and Python.

The issue is that there is a menu something like this enter image description here if I click manually on the arrow button it expands to another submenu from where I need to select a particular field.

I can find this third menu but when I click on it using element.click() instead of expanding the menu and showing me its sub menu items it is showing consolidated contents of all the sub menu.

(Manually the expansion to sub menu is achieved by actually clicking on the small arrow icons before the group names) So how do I actually click on this arrow icons to expand one of the group menu into sub menus.

This is the HTML corresponding to third group menu if it helps.

<div id="node_3_item" class="treeLabelSelected" style="padding-left: 0px; background-position: 0px -24px;">
<span style="background-position: 0px -24px;">XXX Groups</span>
</div>
<div style="display: none;"></div>
</div>

The display: none line is actually hiding the sub menu (as far as I can make out)

Any suggestion on how to handle will be appreciated. Thanks

Note: I have already gone through several questions on SO related to interacting with hidden web elements but they differ with my situation.

Ripon Al Wasim
37.9k42 gold badges159 silver badges179 bronze badges
asked Jul 3, 2013 at 12:34

3 Answers 3

14

Grab the element you want to click:

# Or using xparth or something
element = driver.find_element_by_css_selector(css_selector)

Click it using javascript:

driver.execute_script("$(arguments[0]).click();", element)

NOTE: I'm using jQuery otherwise select it native with javascript

answered Apr 28, 2015 at 12:33

1 Comment

I had to use driver.execute_script("arguments[0].click();", element)
6

You can use JavaScriptExecutor

For Eg. - document.getElementsByClassName('post-tag')[0].click();

Issue that JS via JavaScriptExecutor

 (JavascriptExecutor(webdriver)).executeScript("document.getElementsByClassName('post-tag')[0].click();");
answered Jul 3, 2013 at 12:48

2 Comments

Can you please elaborate a little bit.
I also do not understand. Can we see a real world text example? I'm doing ptor.driver.executeScript("document.getElementsByClassName('logout')[0].click();"); and it throws UnknownError: {"errorMessage":"'undefined' is not a function (evaluating 'document.getElementsByClassName('logout')[0].click()')"
0

If your application uses jQuery you can use it to specify a target element which will simplify your work. E.g.

$('.targetClass')
Chris Pickford
9,0406 gold badges49 silver badges76 bronze badges
answered Jul 3, 2013 at 18:51

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.