I'm having a problem trying to make an auto-register for Discord account, after opening the browser and filling in the necessary information, it comes to choosing the date of birth. Well, here's the problem! Every item that selects the day, month, and year will be a dropbox, and I can't get the values inside that dropbox to scroll or click. I have tried using the wait command to wait for the values to appear, and locate the option I want to select using its text content. But it's not working at all, can someone help me
import imaplib
import email
from bs4 import BeautifulSoup
import selenium.webdriver as webdriver
from time import sleep
import requests
import pandas as pd
from solveRecaptcha import solveRecaptcha
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.proxy import *
df = pd.read_excel('discord.xlsx')
for index, row in df.iterrows():
# Hotmail information get from Excel
Mailname = row['Mail']
Mailpass = row['Passmail']
# Discord information get from Excel
DCusername = row['Dcusername']
DCpassword = row['Dcpass']
# Change IP by proxy server API and print status
response = requests.get("https://app.proxyno1.com/api/change-key-ip/my-apikey")
status = response.json()["message"]
print('Status:', status)
sleep(10)
# Create a proxy object with the updated proxy URL
proxy = Proxy({
'proxyType': ProxyType.MANUAL,
'httpProxy': 'vpdc1.proxyno1.com:19548',
'sslProxy': 'vpdc1.proxyno1.com:19548',
'noProxy': ''})
# Update the capabilities object to use the new proxy
capabilities = webdriver.DesiredCapabilities.CHROME
proxy.add_to_capabilities(capabilities)
# Open the signup page with proxy
driver = webdriver.Chrome(desired_capabilities=capabilities)
driver.get("https://discord.com/register")
WebDriverWait(driver, 10).until(
EC.presence_of_all_elements_located((By.NAME, "email"))
)
driver.find_element(By.NAME, "email").send_keys(Mailname)
driver.find_element(By.NAME, "username").send_keys(DCusername)
driver.find_element(By.NAME, "password").send_keys(DCpassword)
month_element = driver.find_element(By.CLASS_NAME, "month-1Z2bRu").click()
# Wait for the dropdown menu options to be fully loaded
wait = WebDriverWait(driver, 10)
options = wait.until(EC.presence_of_all_elements_located((By.XPATH, "//option")))
# Locate the option to select using its text content
option = next(option for option in options if option.text == "May")
# Select the option by clicking on it
option.click()
sleep(77)
driver.quit()
CodePudding user response:
I managed to disable JS while the drop-down popup was open to peek at the HTML it adds to the DOM. They do not use select
and option
elements, but just div
. You might be able to find the element based on the ID react-select-3-option-4
or the text contents.
CodePudding user response:
To select a specific option from a dropdown menu in Selenium, you can use the Select class and its select_by_visible_text method.
First, you need to import the Select class from selenium.webdriver.support.ui:
from selenium.webdriver.support.ui import Select
Then, you can use the Select class to create a dropdown menu object and select an option from it by its visible text:
# Create a dropdown menu object
dropdown_menu = Select(driver.find_element(By.CLASS_NAME, "month-1Z2bRu"))
# Select the option by its visible text
dropdown_menu.select_by_visible_text("May")
You can use the same approach to select options from the day and year dropdown menus as well.
Note: Make sure to wait for the dropdown menu element to be present on the page before trying to create the Select object. You can use the WebDriverWait class and its until method to wait for the element to be present, as you are already doing in your code.
I hope this helps! Let me know if you have any questions.