So i automated the task of login into a discordserver and posting a text using Selenium. All works fine but my goal is to make an inputbox for the email and password. The user inputs the information and presses save and the password and mail is supposed to write itsself into the code and save.
What are the best approaches for this? I'm still pretty new to python so go easy on me.
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
driver = webdriver.Firefox()
url = "https://discordapp.com/channels/530588470905929729/538868623981412362"
driver.get(url)
email = WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH,"//input[#type='email']")))
email.send_keys("Mail#mail.com")
password = WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH,"//input[#type='password']")))
password.send_keys("Password" + Keys.ENTER)
sleep(5)
textbox = WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH,"//textarea[#placeholder='Message #bot-commands']")))
textbox.send_keys("!work" + Keys.ENTER)
sleep(30)
driver.quit()
Related
0
I am trying to do a tutorial and learn Selenium in python however i cant seem to get Selenium to enter the password into the password field/form box. It enters the email addres perfectly fine, and inside the code the password is typed correctly however the website returns it as "Incorrect password entered". However when i type the password in manually it logs in as it is correct. I have removed the email and password for security
I am using:
Python v3.9
Chrome v87
This is the URL i am practicing on:
https://www.aria.co.uk/myAria/ShoppingBasket?action=checkout
And this is my current code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
import time
# Open Chromedriver
driver = webdriver.Chrome(r"C:\Users\Ste1337\Desktop\chromedriver\chromedriver.exe")
# Open webpage
driver.get("https://www.aria.co.uk/SuperSpecials/Other+products/ASUS+ROG+Pugio+2+Wireless+Optical+RGB+Gaming+Mouse?productId=72427")
#https://www.aria.co.uk/Products/Components/Graphics+Cards/NVIDIA+GeForce/GeForce+RTX+3060+Ti/Palit+GeForce+RTX+3060+Ti+Dual+8GB+GPU?productId=73054
# Click "Add to Basket" or refresh page if out of stock
try:
element = WebDriverWait(driver, 1).until(EC.presence_of_element_located((By.XPATH, "Out of Stock!")))
time.sleep(5)
browser.refresh()
except:
button = driver.find_element_by_id("addQuantityButton")
button.click()
basket = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.ID, "basketContent")))
basket.click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//img[contains(#src,'/static/images/checkoutv2.png')]"))).click()
login = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.NAME,"login[email]")))
login.send_keys("testuser#hotmail.co.uk")
login.send_keys(Keys.TAB)
driver.implicitly_wait(2)
login.send_keys("password")
driver.implicitly_wait(2)
login.send_keys(Keys.ENTER)
You haven't defined somewhere to put the password. Currently, the password in MEANT to be entered in the same place as the email. To change that, define where the password is meant to go. This is how I did it:
passwrd = driver.find_element_by_xpath("/html/body/div[4]/div[1]/div[2]/form/div/h1/div[3]/div/div/input[2]")
passwrd.send_keys("password")
So in total, the code should look like this:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
import time
# Open Chromedriver
driver = webdriver.Chrome(r"C:\Users\eesam\AppData\Local\Programs\Python\Python39\Scripts\chromedriver.exe")
# Open webpage
driver.get("https://www.aria.co.uk/SuperSpecials/Other+products/ASUS+ROG+Pugio+2+Wireless+Optical+RGB+Gaming+Mouse?productId=72427")
#https://www.aria.co.uk/Products/Components/Graphics+Cards/NVIDIA+GeForce/GeForce+RTX+3060+Ti/Palit+GeForce+RTX+3060+Ti+Dual+8GB+GPU?productId=73054
# Click "Add to Basket" or refresh page if out of stock
try:
element = WebDriverWait(driver, 1).until(EC.presence_of_element_located((By.XPATH, "Out of Stock!")))
time.sleep(5)
browser.refresh()
except:
button = driver.find_element_by_id("addQuantityButton")
button.click()
basket = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.ID, "basketContent")))
basket.click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//img[contains(#src,'/static/images/checkoutv2.png')]"))).click()
login = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.NAME,"login[email]")))
login.send_keys("testuser#hotmail.co.uk")
login.send_keys(Keys.TAB)
driver.implicitly_wait(2)
passwrd = driver.find_element_by_xpath("/html/body/div[4]/div[1]/div[2]/form/div/h1/div[3]/div/div/input[2]")
passwrd.send_keys("password")
driver.implicitly_wait(2)
login.send_keys(Keys.ENTER)
I'm trying to log into my twitter account by using selenium. The filling of username and password is working perfectly, but when pressing the login-button nothing happens.
self.driver.find_element_by_xpath('//*[#id="react-root"]/div/div/div[2]/main/div/div/form/div/div[3]/div').click()
I looked into the html-code and the aria-haspopup is on false. Is there any way I can set it on true so I can click the button?
Greets
Your xpath is working well on twitter's login page (https://twitter.com/login). Maybe you're trying to login on other page.
I'm providing small piece of code for logging into twitter. I used another xpaths and WebDriverWait for waiting until login form would be displayed.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
driver.get('https://twitter.com/login')
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//input[#name='session[username_or_email]' and #data-focusable='true']")))
driver.find_element_by_xpath("//input[#name='session[username_or_email]' and #data-focusable='true']").send_keys('login')
driver.find_element_by_xpath("//input[#name='session[password]' and #data-focusable='true']").send_keys('password')
driver.find_element_by_xpath("//div[#data-testid='LoginForm_Login_Button']").click()
Try to do it like this:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.get('https://twitter.com/login')
email = driver.find_element(By.NAME, 'email')
email.clear()
email.send_keys(EMAIL)
password = driver.find_element(By.NAME, 'pass')
password.clear()
password.send_keys(PASSWORD)
password.send_keys(Keys.RETURN) # Login with ENTER button
My ultimate goal is to simply login but there's 2 problem:
My code is unable to detect the ID to input email/password
The random characters in ID value keeps changing (id=login-email_k9et69del)
Your assistant will be greatly appreciated!
#from selenium.webdriver.common.keys import Keys
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
#create Chrome session
driver = webdriver.Chrome("C:\chromedriver.exe")
driver.get('https://www.jetblue.com/signin')
#login
#wait.until(EC.visibility_of_element_located((By.id, "emailLabel")));
username = driver.find_element_by_id("email").send_keys("xxx#gmail.com")
password = driver.find_element_by_id("Password").send_keys("xx")
screenshot inspect
The Id's that you are using are not correct.
You can use the below locators.
driver.find_element_by_css_selector("input[type='email']").send_keys("email goes here")
driver.find_element_by_css_selector("input[type='password']").send_keys ("password goes here")
You can check if the locators is correct in the browser dev tools. Check this post to know how to work with dev tools in browser dev tools.
Im using Selenium (Python) and am trying to log myself into the discord Website (https://discordapp.com/login) but all my code does is load the page and thats it. I tried all, Css selectors, XPath EVERYTHING. Does anyone have suggestions?
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
browser = webdriver.Firefox()
browser.get('https://discordapp.com/login')
assert 'discordapp' in browser.title
elem = browser.find_element_by_css_selector("input[type='email']")
elem.send_keys("itsolidude#gmail.com")
elem1 = browser.find_element_by_css_selector("input[type='password']")
elem1.send_keys("password" + Keys.ENTER)
Try this below code, where I added the synchronization and tested on Firefox using
python.
You have to add the below import
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
Code:
url = "https://discordapp.com/login"
driver.get(url)
email = WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH,"//input[#type='email']")))
email.send_keys("test#test.com")
If you wanna log in on discord server using selenium(python)then you can use my code
Just add your credentials in the code :)
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
driver = webdriver.Chrome()
driver.get("https://discord.com/login")
time.sleep(6)
username_input = driver.find_element_by_name('email')
username_input.send_keys("enter-your-username-here")
password_input = driver.find_element_by_name('password')
password_input.send_keys("Enter-your-password-here")
login_button = driver.find_element_by_xpath('//*[#id="app-mount"]/div[2]/div/div[2]/div/div/form/div/div/div[1]/div[3]/button[2]')
login_button.click()
I am trying to log in into my linkedin using python selenium. I am able to open my homepage but after that I want to open the following link present on my homepage
<a href="/profile/edit?trk=nav_responsive_sub_nav_edit_profile">
Edit Profile
</a>
I used the following code which allows me to open my homepage-
import getpass
from selenium import webdriver
from bs4 import BeautifulSoup
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
url = "https://www.linkedin.com/uas/login"
driver = webdriver.Firefox()
driver.get(url)
username = 'email-id'
password = 'password'
user = driver.find_element_by_name("session_key")
for j in username:
user.send_keys(j)
pasw = driver.find_element_by_name("session_password")
for j in password:
pasw.send_keys(j)
driver.find_element_by_css_selector("div.form-buttons>input").click()
driver.find_element_by_link_text("Edit Profile").click()
but i get the following error message-
selenium.common.exceptions.NoSuchElementException: Message: Unable to
locate element: {"method":"link text","selector":"Edit Profile"}
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
import urllib, os, urllib.request
import time
driver = webdriver.Safari()
usrName = 'your_email'
pssWrd = "your_password"
driver.maximize_window()
driver.get("https://www.linkedin.com/uas/login?")
driver.find_element_by_name('session_key').send_keys(usrName)
driver.find_element_by_class_name('password').send_keys(pssWrd)
driver.find_element_by_name('signin').click()
It sounds likely that your problem can be solved by waiting explicitly for the elements to be present on the page. See section 5.1 Explicit Waits of the following documentation
http://selenium-python.readthedocs.io/waits.html
Something like this:
wait = WebDriverWait(driver, 10)
element = wait.until(EC.element_to_be_clickable((By.ID, 'someid')))
Note: the explicit wait should be used after you've entered your username, password and clicked submit
Seems that "Edit Profile" is just an option for "Profile" drop-down menu, so it's not visible initialy. You should click on "Profile" first to open drop-down menu. Try:
driver.find_element_by_link_text("Profile").click()
driver.find_element_by_link_text("Edit Profile").click()
UPDATE
Using XPath:
driver.find_element_by_xpath('//a[#class="nav-link"][contains(text(),"Profile")]').click()
driver.find_element_by_xpath('//a[#href="/profile/edit?trk=nav_responsive_sub_nav_edit_profile"]').click()