Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
213 views
in Technique[技术] by (71.8m points)

Selenium selecting from mutilple dropdown with same class - problem python

I'm having 3 drop downs on same div and i want to select the first parameter of each class. It's look like this: enter image description here

I Wrote this code:

fields= driver.find_elements_by_class_name("masked-select-inner")

for test in fields:
    test.click()
    driver.find_element_by_class_name("list").find_elements_by_tag_name("li")[1].click()
    WebDriverWait(driver, 10)

It's successfuly choosing the first field but in the second field the list open and then i get an error:

is not clickable at point (890, 433). Other element would receive the click: <span>...</span>

This is the site

question from:https://stackoverflow.com/questions/66048650/selenium-selecting-from-mutilple-dropdown-with-same-class-problem-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

driver.find_element_by_class_name("list") will always select the first list of drop-down options

You need to use test as context node:

fields= driver.find_elements_by_class_name("masked-select-inner")
for test in fields:
    test.click()
    test.find_element_by_class_name("list").find_elements_by_tag_name("li")[1].click()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...