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()
Related
Ive been attempting to use selenium to go through elements on soundclouds website and am having trouble interacting with the input tags. When I try to write in the input tag of the class "headerSearch__input" with the send keys command, I get back the error "Message: element not interactable". May someone please explain to me what im doing wrong?
from tkinter import *
import random
import urllib.request
from bs4 import BeautifulSoup
from selenium import webdriver
import time
import requests
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.chrome.options import Options
driver = webdriver.Chrome(executable_path='/Users/quanahbennett/PycharmProjects/SeleniumTest/chromedriver')
url= "https://soundcloud.com/"
driver.get(url)
#time.sleep(30)
wait = WebDriverWait(driver, 30)
#link = driver.find_elements_by_link_text("Sign in")
#link[0].click()
#driver.execute_script("arguments[0].click();", link[0])
#SUCCESFUL LOGIN BUTTON PUSH
#please = driver.find_element_by_css_selector('button.frontHero__loginButton')
#please.click()
attempt = driver.find_element_by_css_selector('input.headerSearch__input')
time.sleep(10)
attempt.send_keys('Hello')
breakpoint()
#driver.quit()
The locator - input.headerSearch__input is highlighting two different elements in the DOM. Its important to find unique locators. Link to refer
And also close the cookie pop-up. And then try to interact with elements.
Try like below and confirm.
driver.get("https://soundcloud.com/")
wait = WebDriverWait(driver,30)
# Click on Accept cookies button
wait.until(EC.element_to_be_clickable((By.ID,"onetrust-accept-btn-handler"))).click()
search_field = wait.until(EC.element_to_be_clickable((By.XPATH,"//div[#id='content']//input")))
search_field.send_keys("Sample text")
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)
when i compile my code it log in but the line that should click on the page does not work.
thats my code :
from selenium import webdriver
from Config import keys
import time
def order(k):
driver = webdriver.Chrome('driver\chromedriver.exe')
driver.get(k['product_url'])
username ="gmail"
pw ="password"
#Enter The Pw & email fb
driver.find_element_by_xpath('//*[#id="email"]').send_keys(username)
driver.find_element_by_xpath('//*[#id="pass"]').send_keys(pw)
#Click on cnx button
driver.find_element_by_xpath('//*[#id="u_0_b"]').click()
#go to the page
# here is the problem
driver.find_element_by_xpath('//*[#id="mount_0_0"]/div/div/div[1]/div[3]/div/div[1]/div/div/ul/li[2]/span/div/a').click()
driver.find_element_by_xpath('//*[#id="mount_0_0"]/div/div/div[2]/div/div/div/div/div/div[2]/div/div/div/div[3]/div/div/div[1]/div/a/span').click()
driver.page_source()
if __name__=='__main__':
order(keys)
Could be due to synchronization issue try to induce WebDriverWait :
wait = WebDriverWait(driver, 20)
wait.until(EC.element_to_be_clickable((By.XPATH, "//*[#id='mount_0_0']/div/div/div[1]/div[3]/div/div[1]/div/div/ul/li[2]/span/div/a"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//*[#id='mount_0_0'']/div/div/div[2]/div/div/div/div/div/div[2]/div/div/div/div[3]/div/div/div[1]/div/a/span"))).click()
Note : please add below imports to your solution
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
After checking on the Facebook website, '//*[#id="mount_0_0"]' is the xpath of the main container. For the button you are trying to click, the xpath I have found is :
//*[#id="mount_0_0"]/div/div/div[1]/div[3]/div/div[1]/div/div/ul/li[2]/span/div/a
Maybe you could try with this one ?
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
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()