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)
Related
I am trying to login to my Garmin connect account. I can enter the website by cannot get rid of the window to accept or reject cookies. Would you have a solution for this ? Here is my code:
Thanks a lot!
from selenium import webdriver
from selenium.webdriver import ActionChains
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.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
import time
options = webdriver.ChromeOptions()
options.add_experimental_option("prefs", {"profile.default_content_setting_values.cookies": 1})
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=options)
driver.get("https://connect.garmin.com/signin/") #loading page
wait = WebDriverWait(driver, 20) #defining webdriver wait
#defining username and password
username = 'xxxxx'
password = 'xxxxx\n' #\n will act as enter key
def login():
wait.until(EC.visibility_of_element_located((By.XPATH, "//iframe[#id='gauth-widget-frame-gauth-widget']")))
frameLogin = driver.find_element(By.XPATH, "//iframe[#id='gauth-widget-frame-gauth-widget']")
driver.switch_to.frame(frameLogin)
wait.until(EC.visibility_of_element_located((By.ID, 'username'))).send_keys(username) #userame/email
wait.until(EC.visibility_of_element_located((By.ID, 'password'))).send_keys(password) #password
#try to click on reject cookies
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe[#class='truste_popframe']")))
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe[#class='gwt-Frame']")))
frameCookies = driver.find_element_by_xpath("//iframe[#class='gwt-Frame']")
driver.switch_to.frame(frameCookies)
wait.until(EC.element_to_be_clickable((By.XPATH, "//a[#class='acceptAllButtonLower']"))).click()
login()
You can try to close the popup window, get the xpath of the close button and if it's regular and appears always at loading of page you can close it.
I have one web site like
www.abc.com in this I need to add Email and press continue
and in second page I need to add password and check the check box
so how can I enter the password in 2nd page.
I tired with :
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
uamId = "asas"
driver = webdriver.Chrome("chromedriver")
driver.get("www.abc.com")
print(driver.title)
userid = driver.find_element_by_name("P")
# fill UAM Number
userid.send_keys(a)
elem = driver.find_element_by_xpath('Xpath')
actions = ActionChains(driver)
actions.click(elem).perform()
Before getting the web element you have to validate the element is fully loaded and is clickable / visible.
Also in that specific site you have to click elements in order to insert the email and password.
Your code should look like this:
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
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.keys import Keys
driver = webdriver.Chrome("chromedriver")
wait = WebDriverWait(driver, 20)
driver.get("www.abc.com")
print(driver.title)
#open account menu
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".navigation__menu #account span"))).click()
wait.until(EC.visibility_of_element_located((By.XPATH, "//a[text()='Sign in']"))).click()
#now you will have to switch into the iframe
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[#id='disneyid-iframe']")))
#now you can insert the credentials
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "input[type='email']"))).send_keys(your_email)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "input[type='password']"))).send_keys(your_password)
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
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()
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()