1

The below is a snippet from our html code which appears as a drop down list in the application. I am unable to select a particular value from the drop down list using Select class in Selenium - possibly because it doesn't have "Option" tags?. Is there any way to select the item?

-UPDATE: This has a parent tag which talks about visibility. Basically to tell that elements are visible only if the user clicks the drop down arrow. "< input type="hidden" *****"

For e.g. I need to select 'I am option2' from the list during the test execution.

<div id="xyz" class="DropdownInnerContainer" style="z-index:99999;">
<table id="abc" class="DropdownItemContainer" list="1000020">
    <tr class="">
        <td value="" index="0" title="">&nbsp;
        </td>
        <td class="BorderCell"></td>
    </tr>
    <tr class="">
        <td value="I am option1" index="1" plid="1002827">I am option1</td>
        <td class="BorderCell"></td>
    </tr>
    <tr class="">
        <td value="I am option2" index="2" plid="1002828">I am option2</td>
        <td class="BorderCell"></td>
    </tr>
    <tr class="">
        <td value="I am option3" index="3" plid="1002829">I am option3</td>
        <td class="BorderCell"></td>
    </tr>
    <tr class="">
        <td value="I am option4" index="4" plid="1002830">I am option4</td>
        <td class="BorderCell"></td>
    </tr>
</table>

3 Answers 3

1

If the text inside of the td that you want to select is unique, then you can click the table element with the id of 'abc' and then click the following element. The code provided is C#, but can be translated pretty easily.

IWebElement option = _driver.FindElement(By.XPath("//td[text()='I am option2']"));
Sign up to request clarification or add additional context in comments.

8 Comments

Sorry, I forgot to mention that the drop down list appears hidden unless the user clicks the arrow button.
If that is the case, you will have to create an element from the arrow, click it, then select your option like the example I posted above. Can you update your HTML to include the element you are referring to?
Already tried that too. I get an error : Cannot click on element
Please find the html related to the drop down function: <div class="inputwrap1 ComboBoxInnerContainer" onclick="if (rlEditors$) rlEditors$.onToggleDropdown$('7000','GENERAL_SUBMISSION_ctxxx_tb')">
Is this website made with a css framework, such as materialize css? Check further down in the HTML for a <select> attribute. This behavior is common with a lot of frameworks that create their own elements in the DOM. It looks like this might be a case.
|
1

It appears that since the drop down options were inside a < table >, the Select class was unable to identify the list options. So here's what I did:

First click() the dropdown, which opens up the menu:

driver.findElement(By.xpath(".//*[@id='abc01_tbl']/div/div")).click();

Then pass the value using the contains() method and then click() on it.

driver.findElement(By.xpath(".//*[@id='xyz01_tbl']/tbody/tr/td[1][contains(text(),'I am option2')]")).click();

Comments

1

You can not use Select in this scenario because there is no any select tag for dropdown. Drop down is under table body.

Please use below xpath for select option form drop down.

driver.findElement(By.xpath("//table[@id='abc']/tr[td[text()='your option text']]/td"));

Comments

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.