栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在React-Select Component下拉菜单中使用Python Selenium选择值?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在React-Select Component下拉菜单中使用Python Selenium选择值?

您的页面使用React Select Component。正如小组中其他讨论的那样,您必须像手动步骤一样完全自动化这种情况,

  1. 单击难以处理的元素。
  2. 等待下拉菜单出现。
  3. 单击下拉列表中的值。

这里有两种情况

  • 无值时选择
  • 选择何时有价值。

我假设页面具有与之相似的单个选择框,并且默认情况下未选择性别值。在下面的代码中,我正在选择男性案例。选择男性后,我将其更改为女性。

选择没有价值的下拉菜单

# this is click the div..Select-placeholder element which is intractabledriver.find_element_by_css_selector('.Select--single .Select-placeholder').click()# Then we are waiting for the dropdown value to appearwait = WebDriverWait(driver, 60)male= wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, '.Select-option#react-select-5--option-0)')))# Click the element male option value of the dropdownmale.click()

用值选择下拉列表

# this is click the div.Select-value element which is intractabledriver.find_element_by_css_selector('.Select--single .Select-value').click()female = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, '.Select-option#react-select-5--option-1)')))# Click the element female option value of the dropdownfemale.click()

获取选择的值

 selected_value=driver.find_element_by_css_selector('.Select--single .Select-value').text print(selected_value)

清除所选值

 selected_value=driver.find_element_by_css_selector('.Select--single Select-clear').click()


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/402668.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号