Issue
So, I'm making a Selenium bot that makes discord accounts. The issue that I'm facing is that I cannot access the date (so I can't enter my date of birth ). the website is this one: https://discord.com/register I have been stuck on this for a couple of hours and I still can't figure out how to change the date of birth with Selenium. I have tried searching the months in the source code but I wasn't able to find them , this makes me think that it's impossible to access something that doesn't exist. So can anyone help me?
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--incognito")
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("https://discord.com/register")
mail=driver.find_element_by_name("email")
mail.send_keys("[email protected]")
username=driver.find_element_by_name("username")
username.send_keys("some username")
password=driver.find_element_by_name("password")
password.send_keys("some password")
This is what I have so far
Solution
You can make the same action as a user would do.
First, use explicit waits to make your script stable. For this import from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By
Note, that this especially helpful to wait till your month
input is clickable.
Second,
Use CSS
or XPath
selectors to make your script stable. In your case it is better to use css because for class names you just put a .
before a class.
Third. Simulate pressing Enter with Selenium. For this import
from selenium.webdriver.common.keys import Keys
and apply enter with .send_keys(Keys.ENTER)
Use the same strategy for date and year.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--incognito")
driver = webdriver.Chrome(executable_path='/snap/bin/chromium.chromedriver', chrome_options=chrome_options)
driver.get("https://discord.com/register")
wait = WebDriverWait(driver, 10)
mail = wait.until(EC.element_to_be_clickable((By.NAME, "email")))
mail.send_keys("[email protected]")
username = wait.until(EC.element_to_be_clickable((By.NAME, "username")))
username.send_keys("some username")
password = wait.until(EC.element_to_be_clickable((By.NAME, "password")))
password.send_keys("some password")
month = driver.find_element_by_css_selector(".css-1hwfws3")
month.click()
month_input = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".inputMonth-IGgn-0 input")))
month_input.send_keys("December")
month_input.send_keys(Keys.ENTER)
P.S. There are other ways as well. What I propose should be reliable.
Answered By - vitaliis
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.