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,320 points
15,180 views

2 answers to this question.

+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,910 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 28, 2018 in Selenium by nsv999
• 5,500 points
5,134 views
0 votes
2 answers

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,500 points
13,649 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,131 views
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,910 points
7,209 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,865 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,910 points
11,217 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,910 points
2,751 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP