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,220 points
5,236 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,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,110 points
1,656 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
• 6,220 points
2,088 views
+1 vote
2 answers
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,110 points
916 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
1,102 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
838 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
2,331 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
341 views