0

sorry can`t share the data.

I have a filter of 3 dropdown lists all sharing the same id using div class, and when i tried to use select, i received this error "Message: Select only works on elements, not on "

Hope someone help me automate the selection of 3 fields.

Thanks in advance

2 Answers2

0

"Message: Select only works on elements, not on" means,

  1. Firstly, The above exception mean, Select class of selenium which you are using to choose a dropdown value works only for the HTML structure with select tag as below. It will not work for div/ul/li or any other tag.

<select name="cars" id="cars">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>

2)Selenium clicks has to be used to handle the dropdown with div tag. Refer stackoverflow link which has a solution for div tag type dropdown

3)For the elements where each and every attributes are similar, you can use the xpath as below, here '2' in the xpath means to choose the second element, similarly '3' for the third element and so on

driver.find_element_by_xpath("(//div[@class='class name'])[2]")
        or
driver.find_element_by_xpath("(//div[@class='class name'])[position()=2]")
       or
'''call find elements method instead of find element which will fetch all the elements 
 with the same class and loop through each element and perform action as below'''
all_div = driver.find_elements_by_xpath("//div[@class='class name']")
for div in all_div :
  #action to perform on each element of div
Nischitha K N
  • 397
  • 1
  • 8
-1

It would be better if you had an example with dummy data. From what I understand, you're trying to select an element by it's id but the id must be unique for an element. You will want to give your elements the same name, not the same id.and call them with the method find_elements_by_name as find_element_by_id will only return the first element with a corresponding id. Doc here

LittleSoap
  • 74
  • 5