如何使用 Selenium select Discord 网站中的出生日期部分中的月份
How to select the month within Date Of Birth section within Discord website using Selenium
我正在尝试让 Selenium 自动化 Discord 出生日期
到目前为止我已经知道了,但不知道如何把它带到 select 一个随机的月份
# Discord Date Of Birth
month = driver.find_element(By.CSS_SELECTOR,'#app-mount > div.app-3xd6d0 > div > div > div > form > div > div > div.container-2UAUAG.marginTop20-2T8ZJx > div.inputs-3ELGTz > div.month-1Z2bRu > div > div > div > div')
month.click()
需要的元素是动态元素,所以要select月为四月 DOB 部分 Discord webpage you need to induce WebDriverWait for the and you can use the following :
使用 XPATH:
driver.get('https://discord.com/register')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[starts-with(@class, 'month')]//div[text()='Select']"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='css-dwar6a-menu']//div[text()='April']"))).click()
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
截图:
我正在尝试让 Selenium 自动化 Discord 出生日期
到目前为止我已经知道了,但不知道如何把它带到 select 一个随机的月份
# Discord Date Of Birth
month = driver.find_element(By.CSS_SELECTOR,'#app-mount > div.app-3xd6d0 > div > div > div > form > div > div > div.container-2UAUAG.marginTop20-2T8ZJx > div.inputs-3ELGTz > div.month-1Z2bRu > div > div > div > div')
month.click()
需要的元素是动态元素,所以要select月为四月 DOB 部分 Discord webpage you need to induce WebDriverWait for the
使用 XPATH:
driver.get('https://discord.com/register') WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[starts-with(@class, 'month')]//div[text()='Select']"))).click() WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='css-dwar6a-menu']//div[text()='April']"))).click()
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
截图: