Select Selenium 中 react-select 下拉列表中的项目 Python
Select item inside a react-select dropdown list in Selenium with Python
在那个网站上,我正在寻找如何在“单一”下拉框和“分组”下拉框中 select 项(例如“绿色”)。
我尝试先点击下拉菜单,然后尝试找到其中的元素进行点击,但我不能
你有什么想法吗?对于分组下拉菜单,我什至找不到单击它的 xpath
提前致谢
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()
点击不可见的选项:
option=driver.find_element_by_xpath("//*[text()='Silver']")
driver.execute_script("arguments[0].scrollIntoView();", option)
option.click()
你必须先滚动到那个然后点击
To select Green from the Single dropdown box you need to induce WebDriverWait for the element_to_be_clickable()
and you can use either of the following :
driver.get("https://react-select.com/home")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.basic-single > div.select__control > div.select__value-container"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[contains(@class, 'select__menu')]/div[contains(@class, 'select__menu-list')]//div[contains(@class, 'select__option') and text()='Green']"))).click()
- 浏览器快照:
在那个网站上,我正在寻找如何在“单一”下拉框和“分组”下拉框中 select 项(例如“绿色”)。
我尝试先点击下拉菜单,然后尝试找到其中的元素进行点击,但我不能
你有什么想法吗?对于分组下拉菜单,我什至找不到单击它的 xpath
提前致谢
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()
点击不可见的选项:
option=driver.find_element_by_xpath("//*[text()='Silver']")
driver.execute_script("arguments[0].scrollIntoView();", option)
option.click()
你必须先滚动到那个然后点击
To select Green from the Single dropdown box you need to induce WebDriverWait for the element_to_be_clickable()
and you can use either of the following
driver.get("https://react-select.com/home")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.basic-single > div.select__control > div.select__value-container"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[contains(@class, 'select__menu')]/div[contains(@class, 'select__menu-list')]//div[contains(@class, 'select__option') and text()='Green']"))).click()
- 浏览器快照: