如何选择不在 DOM 中的元素
How to choose an element that is not in DOM
网站https://account.mail.ru/signup
我尝试在 select "Дата рождения" - "День" 中占据一些位置。 Xpath for expant select "День" //span[text()='День']/ancestor::div[@class='Select-control']
然后尝试 select 某天,但是 POM 中不存在当天的位置。
请帮我改正 XPATH。
您可以尝试使用以下代码从下拉框中选择 select 天:
driver.get('https://account.mail.ru/signup')
driver.maximize_window()
wait = WebDriverWait(driver, 20)
wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@id='react-select-2--value']//div[@class='Select-placeholder']"))).click()
element = wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@class='Select-option']//span[contains(text(),'12')]"))).click()
注意:请将以下导入添加到您的解决方案
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
检查 react-select 下拉列表
- 打开chrome浏览器
- 打开开发工具
- 导航到元素
- Select 事件侦听器
- Select模糊
- 点击文档下的删除
网站https://account.mail.ru/signup
我尝试在 select "Дата рождения" - "День" 中占据一些位置。 Xpath for expant select "День" //span[text()='День']/ancestor::div[@class='Select-control']
然后尝试 select 某天,但是 POM 中不存在当天的位置。
请帮我改正 XPATH。
您可以尝试使用以下代码从下拉框中选择 select 天:
driver.get('https://account.mail.ru/signup')
driver.maximize_window()
wait = WebDriverWait(driver, 20)
wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@id='react-select-2--value']//div[@class='Select-placeholder']"))).click()
element = wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@class='Select-option']//span[contains(text(),'12')]"))).click()
注意:请将以下导入添加到您的解决方案
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
检查 react-select 下拉列表
- 打开chrome浏览器
- 打开开发工具
- 导航到元素
- Select 事件侦听器
- Select模糊
- 点击文档下的删除