Skip to content
Advertisement

AttributeError: ‘WebElement’ object has no attribute ‘select_by_value’ selecting dropdown menu using Selenium

I am trying to find menu prices for certain fast food restaurants from this website by different state. There is a dropdown menu where different states are the options. After I select a state (for example, California), I want to web scrape the different prices of their Ice Cream. However, I keep getting the same error message preventing me from getting the data. I think it works fine until going to the website, but it can’t seem to select it by state. What do I need to do in order to:

  1. Get selenium to accurately select a certain state (California)
  2. Get the menu prices for just the “Ice Cream” category?

The Code is below:

JavaScript

The Error I get is:

JavaScript

A photo of the code + error is below:

Code_Error

Advertisement

Answer

select_by_value() is a method from select class and to use it you have to use the Select(webelement) method.


Solution

To select the option California you can use the following locator strategy:

  • Code Block:

    JavaScript
  • Browser Snapshot:

California

Advertisement