问题
Link example website here
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
Do you have any idea? and with Grouped dropdown I even couldn't find the xpath to click on it
Thank in advance
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()
回答1:
remove @ from text
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
回答2:
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 Locator Strategies:
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()
- Browser Snapshot:
来源:https://stackoverflow.com/questions/65705271/select-item-inside-a-react-select-dropdown-list-in-selenium-with-python