使用Python在Selenium中的react-select下拉列表中选择项目

问题描述:

在此处链接示例网站

在该网站中,我正在寻找如何在单一"商品中选择商品(例如绿色")的方法.下拉框和分组"下拉框.

In that website, I am looking how to select item (e.g "Green") in "Single" dropdown box and "Grouped" dropdown box.

我尝试先单击下拉菜单,然后尝试查找其中的元素以单击,但我做不到

I tried to click to dropdown first and tried to find the element inside it to click but I can't

你有什么主意吗?并通过分组下拉菜单,我什至找不到要单击的xpath

Do you have any idea? and with Grouped dropdown I even couldn't find the xpath to click on it

预先感谢

driver = webdriver.Chrome()
driver.get("https://react-select.com/home")
driver.maximize_window()
driver.implicitly_wait(20)
driver.find_element_by_xpath("//div[@class='select__value-container select__value-container--has-value css-1hwfws3']").click()
driver.find_element_by_xpath("//*[@text()='Green']").click()

从文本中删除@

driver.find_element_by_xpath("//*[text()='Green']").click()

要单击不可见的选项,请执行以下操作:

To click on options that are not visible:

option=driver.find_element_by_xpath("//*[text()='Silver']")
driver.execute_script("arguments[0].scrollIntoView();", option)
option.click()

您必须先滚动至该位置,然后单击

You have to scroll first to that and then click