Drop-down menu option value not working using Selenium (Python)

+1 vote

I am selecting an element from a drop-down menu. Like this:

<select id="games1" class="select" name="games">

    <option value="0">Choose your games:</option>

    <option value="1">Call Of Duty</option>

    <option value="2">Ninja</option>

</select>

First I clicked on it and working fine

inputElementGames = driver.find_element_by_xpath("//select["id='games']).click()

And when I select the element, let's say, Ninja. I tried the different thing with inputElementFruits.send_keys(...) but it did not work.

Jul 9, 2018 in Selenium by Martin
• 4,210 points
2,638 views

2 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
+1 vote

Unless your click is firing ajax call to populate your list, you don't actually need to execute the click. Just find the element and then enumerate the options, selecting the option(s) you want.

Here is an example:

from selenium import webdriver

b = webdriver.Firefox()

b.find_element_by_xpath("//select[@name='element_name']/option[text()='option_text']").click()

 
answered Jul 9, 2018 by Samarpit
• 5,130 points
+1 vote

from selenium.webdriver.support.select import Select

inputElementGames = Select(driver.find_element_by_xpath("//select["id='games'])).options
inputElementGames.select_by_visible_text('Ninja')
answered Nov 28, 2018 by Rijhu mal
Yup. That could also work!

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer

Selenium + Java - drag and drop not working on selenium 3.8

How about you try adding the below ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,030 points
1,004 views
0 votes
1 answer

findElement(By.xpath()) not working using Selenium WebDriver

element = findElement(By.xpath("//*[@test-id='test-username']"); element = findElement(By.xpath("//input[@test-id='test-username']"); (*) - any ...READ MORE

answered Apr 18, 2018 in Selenium by code_ninja
• 5,710 points
961 views
0 votes
2 answers

Is it possible to scroll down in a webpage using selenium webdriver programmed on python?

I using next code for facebook for ...READ MORE

answered 4 days ago in Selenium by mslavikas@gmail.com
4,189 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,030 points
56 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
420 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
43 views
0 votes
1 answer

Select a drop down value of angular js application using selenium using text

To select drop down use following, driver.findElements(By.className("Your dropdown ...READ MORE

answered Jun 18, 2018 in Selenium by Samarpit
• 5,130 points
1,042 views
0 votes
1 answer

How to login a forum using Selenium with Python

You should try to directly log in ...READ MORE

answered Apr 27, 2018 in Selenium by Samarpit
• 5,130 points
150 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.