0

I am trying to click on an element in dropdown, The element is hidden initially when clicking on it, the list is displayed, I want click on one of the names in the list. I tried using the select drop down.. find by visbile text method but getting an error which say the element is type of input and not dropdown.

I tried using xpath,Css selector, linkname and Partiallinktext but none worked.

HTML for the element which i need to click is as below:

<div class="dropdown" style="display: none;">
<div class="search">
<div class="tree" style="display: block;">
<ul class="open">
<li>
<a class="parent open" href="#"></a>
<a class="current" data-nodeid="7" data-name="Global" data-nodemetadata="Global,Global" data-fullname="Global" href="#">Global</a>
<ul class="open">
<li>
<li>
a data-nodeid="807" data-name="Akram" data-nodemetadata="Akram,akram" data-fullname="Akram" `href="#">Akram</a>`
</li>
<li>

I want to click on 'Akram' element. Any help will be appreciated.

Is there a way of passing Variable name in Xpath String, like in the above case Instead of clicking on 'Akram' by I want to click on any other text, So Is it possible to add this text to variable and use the variable inside the xpath "//div[@class='dropdown']//a[text()='Akram']"

Thanks in advance.

3
  • can you please add a snapshot of what your dropdown looks like ? Commented Nov 20, 2014 at 11:35
  • I cannot upload an image, Adding dropbox link, Pls download and see the img. dropbox.com/s/d8bl9smymeh3eao/test.png?dl=0 Commented May 29, 2015 at 12:56
  • Please check the below answer by @Oleksii. I would suggest you to do the same.. Because for using the Select class and its methods, the dropdown need to be of select type. Commented Jun 2, 2015 at 11:30

1 Answer 1

3

WebDriver doesn't allow to click on hidden elements. Naїve approach is just to perform 2 clicks. First on the drop down and second on the option: click "//div[@class='dropdown']" then it will show up, and you click "//div[@class='dropdown']//a[text()='Akram']". Also there is a possibility that when performing second click, drop down option still could be hidden, in that case you need to wait for them to show up first.

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

3 Comments

Is there a way of passing Variable name in Xpath String, like in the above case Instead of clicking on 'Akram' I want to click on any other text, So Is it possible to add this text to variable and use the variable inside the xpath "//div[@class='dropdown']//a[text()='Akram']"
What language do you use? You need to look for strings concatenation in that language. Possibly you can do like this: String opt = "Akram"; String xpath = "//div[@class='dropdown']//a[text()='" + opt + "']";
I am using Java, Thanks for the help Oleksii Matiiasevych, The above solution worked.

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.