6

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"}

2
  • You can use Xpath here to find link and click..because may be link text has extra spaces or \t,\n...which is not found by link text...CommentedMay 28, 2016 at 6:54
  • driver.find_element_by_xpath("html/body/div[2]/div[2]/div/div[1]/ul/li[2]/ul/li[1]/a").click() is this the right format for using Xpath to find link and click on it?
    – cgkentrus
    CommentedMay 28, 2016 at 7:05

3 Answers 3

1
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() 
4
  • This doesn't answer the questionCommentedNov 3, 2018 at 10:24
  • what am I missing?CommentedNov 13, 2018 at 16:48
  • I think the crux of the OPs thrust is to get to the "Edit Profile" page.CommentedNov 13, 2018 at 19:51
  • Gotcha. The web elements are completely different now. Should I update with a redirect to the edit page now?CommentedNov 14, 2018 at 1:33
1

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

    0

    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() 
    8
    • I tried your suggestion but got the following error:selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"link text","selector":"Profile"}
      – cgkentrus
      CommentedMay 28, 2016 at 6:46
    • Are you sure that you pass authorization and you have access to profile editing option?
      – Andersson
      CommentedMay 28, 2016 at 7:18
    • Yes, I am able to login successfully onto by homepage using the above mentioned code, it even opens up in my firefox which displayes the whole automated process of logging in,but after that it doesn't do anything.
      – cgkentrus
      CommentedMay 28, 2016 at 7:24
    • Thanks for the update. I tried the Xpath method still cannot click on that link-selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"xpath","selector":"//a[@class=\"nav-link\"][contains(text(),\"Profile\")]"}
      – cgkentrus
      CommentedMay 28, 2016 at 8:09
    • 1
      Don't use a .sleep(). Use a WebDriverWait instead and wait for the element to be clickable... then click it. .sleep() is not dynamic enough... it may not be long enough some times and too long others. A proper wait will execute as soon as the element is available but time out if it takes too long.
      – JeffC
      CommentedMay 29, 2016 at 4:23

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.