Stella
Stella

Reputation: 1564

`.select_by_visible_text()` is failed to select element?

I'm not sure why .select_by_visible_text() is failed to select element?

take this website as example:https://www-01.ibm.com/products/hardware/configurator/americas/bhui/launchNI.wss

driver.get("https://www-01.ibm.com/products/hardware/configurator/americas/bhui/launchNI.wss")
driver.find_element_by_id("modelnumber").send_keys('7383AC1')
driver.find_element_by_name("submit").click()
FC='A1G7'
option_el=find_element_by_xpath("//option[contains(text(),'%s')]" %FC)
select_el=option_el.find_element_by_xpath("..")
Select(select_el).select_by_visible_text(FC)

enter image description here

Upvotes: 2

Views: 4889

Answers (2)

jcomeau_ictx
jcomeau_ictx

Reputation: 38482

Select.select_by_visible_text() requires the full text of the option desired, not just a piece of it. that's why Stella's solution works and yours does not, but it's also more efficient.

Upvotes: 2

Stella
Stella

Reputation: 1564

driver.get("https://www-01.ibm.com/products/hardware/configurator/americas/bhui/launchNI.wss")
driver.find_element_by_id("modelnumber").send_keys('7383AC1')
driver.find_element_by_name("submit").click()
FC='A1G7'
option_el=find_element_by_xpath("//option[contains(text(),'%s')]" %FC)
option_el.click()

take click() instead of select

Upvotes: 3

Related Questions