I'm trying to log in Discord using selenium in Python, so that I can later run some searches and return data.
So far this is what I have:
from selenium import webdriver
browser = webdriver.Chrome(executable_path='C:\\xyz\\chromedriver_win32\\chromedriver.exe')
browser.get('https://discordapp.com/login')
username = browser.find_element_by_id("register-email")
username.send_keys("[email protected]")
password = browser.find_element_by_id("register-password")
password.send_keys("password123")
The next step would be to submit id and password with the Login button, but I do not know how to find that element by name.
browser.find_element_by_name("login").click()
How can I find that element programatically?
It doesn't look like the Login button element has a name attribute equal to 'login', so in this case you wouldn't be able to find it with your browser.find_element_by_name("login").click() statement.
If you're using Google Chrome, you can use the Developer Tools (F12 on Windows, I believe, CMD + Shift + I on Mac) to find the element within the DOM tree. If it had a name attribute, you'd be able to locate that here. In this case it doesn't, but we're able to right click on the element within the DOM tree and can extract another way of finding the element, such as 'Copy XPath' or 'Copy selector'.
Cleaning up the extracted XPath, you could use the following to click the element:
browser.find_element_by_xpath("//*button[contains(., 'Login')").click()
If you open the developers tools using F12 you can put the mouse cruiser on elements in the html and they will be highlighted in the UI.
The login button has class btn-primary
browser.find_element_by_class_name("btn-primary").click()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With