Not able to select the item in t drop down list.

117 views
Skip to first unread message

Sunitha S

unread,
Jun 6, 2017, 9:56:35 AM6/6/17
to Selenium Users
Hi,

I was trying to select the item in drop down list.Drop down button is clicked but item is not selected .I have used this code.

@FindBy(xpath="//select[@id='requestreason']")
    private WebElement reuestReasonListbox;
   
    public void selectRequestReason()
    {
    reuestReasonListbox.click();
    Select sel = new Select(driver.findElement(By.id("requestreason")));
        sel.selectByVisibleText("STARS");
    //sel.selectByIndex(3);
    }
   
Can any one suggest me the solution.

Monika Singhal

unread,
Jun 6, 2017, 10:58:00 PM6/6/17
to Selenium Users
It will be great if you can attach the screenshot
of the drop down HTML.

Sunitha S

unread,
Jun 7, 2017, 9:31:22 AM6/7/17
to Selenium Users
Hi Monika,

I have attached drop down HTML.Can you please check once.
Dropdown_HTML.PNG

Akshat Gupta

unread,
Jun 7, 2017, 11:18:03 PM6/7/17
to Selenium Users
Try this,


new Select(driver.findElement(By.id("<Enter id of the object>"))).selectByVisibleText("<Enter Option Text>");


Let me know if you face any problem.

Monika Singhal

unread,
Jun 8, 2017, 12:16:59 AM6/8/17
to Selenium Users
I have tried with your HTML. You don't have to write this line:
reuestReasonListbox.click();

Please modify your code to:

System.setProperty("webdriver.gecko.driver", "src/geckodriver");

WebDriver driver = new FirefoxDriver();

driver.get("link of your website");

Select select= new Select(driver.findElement(By.id("requestreason")));

select.selectByVisibleText("Medicare Risk Review");

PGF Bangalore English

unread,
Jun 8, 2017, 9:29:09 AM6/8/17
to Selenium Users
Hi Akshat,

I have tried but it's not working. Type mismatch  can't convert from void to select 

Select sel = new Select(driver.findElement(By.id("requestreason"))).selectByVisibleText("HEDIS");



PGF Bangalore English

unread,
Jun 8, 2017, 9:34:19 AM6/8/17
to Selenium Users
Hi Monika,

Thank you so much for your reply. I have tried but item is not selected.

Select sel = new Select(driver.findElement(By.id("requestreason")));
sel.selectByVisibleText("HEDIS");


Akshat Gupta

unread,
Jun 8, 2017, 9:58:01 AM6/8/17
to Selenium Users
new Select(driver.findElement(By.id("requestreason"))).selectByVisibleText("HEDIS");


Just use this.

void error will not be there.

PGF Bangalore English

unread,
Jun 8, 2017, 12:12:01 PM6/8/17
to Selenium Users
Thank you Akshat .I have tried with this " new Select(driver.findElement(By.id("requestreason"))).selectByVisibleText("HEDIS"); "

No Error but item is not selected.I'm not getting what's the problem is 


Akshat Gupta

unread,
Jun 8, 2017, 12:17:32 PM6/8/17
to Selenium Users
You want to click it or just want to select the expected option ?

PGF Bangalore English

unread,
Jun 8, 2017, 12:22:33 PM6/8/17
to Selenium Users
I was trying to select the option.I have attached the snapshot of output.Program executed successfully but item is not selected.


Output.PNG

Monika Singhal

unread,
Jun 8, 2017, 2:17:01 PM6/8/17
to Selenium Users
TRY THIS:

WebElement select_element= driver.findElement(By.id("requestreason"));

select_element.findElement(By.xpath("./option[text()='Stars']")).click();


YOU CAN REPLACE IT BY ANY TEXT YOU WANT TO SELECT.

PGF Bangalore English

unread,
Jun 8, 2017, 3:46:50 PM6/8/17
to Selenium Users
Monika, I have tried what  you have suggested but item is not selected.I have tried several times with different options
Output3.PNG

Akshat Gupta

unread,
Jun 8, 2017, 10:34:20 PM6/8/17
to Selenium Users
Use value field instead of Text, it might help. You have to give value=2 for HEDIS

There is another option, you can go for index for selection.

As per your screenshot attached, your test cases are passing perfectly. Debug it once and inspect the line where you are finding element.

Akshat Gupta

unread,
Jun 8, 2017, 10:49:43 PM6/8/17
to Selenium Users
Hi,

if it doesn't work give the url of the website, i will see.

Sunitha Gummadi

unread,
Jun 13, 2017, 10:14:38 AM6/13/17
to Selenium Users
Hi Akshat,

I have tried with the value but item is not selected.Can you check the snapshot once. 


Debug_Output.PNG

Moises Siles

unread,
Jun 13, 2017, 5:05:14 PM6/13/17
to seleniu...@googlegroups.com
also could you take a look of the webelement, there are some dropdowns as input elements instead of select

On Tue, Jun 13, 2017 at 8:14 AM, Sunitha Gummadi <sunit...@gmail.com> wrote:
Hi Akshat,

I have tried with the value but item is not selected.Can you check the snapshot once. 


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/92be63df-bbfe-43c4-ae56-513ea04fdbbd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Moises Siles

unread,
Jun 13, 2017, 5:05:40 PM6/13/17
to seleniu...@googlegroups.com
I mean, take a screenshot of the html

On Tue, Jun 13, 2017 at 3:04 PM, Moises Siles <moises...@gmail.com> wrote:
also could you take a look of the webelement, there are some dropdowns as input elements instead of select
On Tue, Jun 13, 2017 at 8:14 AM, Sunitha Gummadi <sunit...@gmail.com> wrote:
Hi Akshat,

I have tried with the value but item is not selected.Can you check the snapshot once. 


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

Sunitha Gummadi

unread,
Jun 14, 2017, 9:41:41 AM6/14/17
to Selenium Users
Hi,

Select class is used for  Drop down. 

Dropdown-HTML.PNG

Sunitha Gummadi

unread,
Jun 14, 2017, 12:26:38 PM6/14/17
to Selenium Users
Hi,

I'm able to print the Dropdown items but i was not able to select the item .I have tried 3 methods like  "selectByVisibleText", "selectByValue"  and "selectByIndex" but no use.

DropdownList_Output.PNG

Akshat Gupta

unread,
Jun 15, 2017, 6:10:14 AM6/15/17
to Selenium Users
Hi,

Try Selenium IDE recorder to execute this. After that export the test script and compare with your code.
Reply all
Reply to author
Forward
0 new messages