Python Forum
locating element with selenium after login
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
locating element with selenium after login
#1
I wrote a script to locate the search bar in my facebook home page. Code for login into my facebook profile using selenium worked perfectly. I got the home page, but the code for locating the search bar is not working correctly. I tried the to locate the search bar using the following code -

elem = driver.find_element_by_name("q")
and I am getting the below error message -
Error:
/usr/bin/python2.7 /home/csurv_4/PycharmProjects/web_parsing/entering_in_page.py Traceback (most recent call last): File "/home/csurv_4/PycharmProjects/web_parsing/entering_in_page.py", line 14, in <module> elem = driver.find_element_by_name("q") File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 487, in find_element_by_name return self.find_element(by=By.NAME, value=name) File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 955, in find_element 'value': value})['value'] File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute self.error_handler.check_response(response) File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: [name="q"]
What is the reason of this error? and what is the solution?
Reply
#2
You either 1) didnt give it time to locate that element (add a time.sleep(3) before finding the name to test to make sure its loaded) or you can try the xpath
/html/body/div[1]/div[2]/div/div[1]/div/div/div/div[1]/div[2]/div/form/div/div/div/div/input[2]
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Selenium suddenly fails to find element Pavel_47 3 6,285 Sep-04-2022, 11:06 AM
Last Post: Pavel_47
  Selenium google login probottpric 0 2,173 Oct-09-2020, 04:19 PM
Last Post: probottpric
  Locating elements via Selenium peterjv26 2 2,464 Oct-02-2020, 07:50 AM
Last Post: peterjv26
  Get element (ID) from website to login Olimpiarob 4 4,242 Jul-28-2020, 01:20 PM
Last Post: Martinelli
  Clicking on element not triggering event in Selenium Python (Event Key is not in data dkaeloredo 2 4,261 Feb-16-2020, 05:50 AM
Last Post: dkaeloredo
  Selenium locating an element. JokerTux 3 2,671 Dec-28-2019, 08:50 AM
Last Post: snippsat
  Selenium returning web element instead of desired text newbie_programmer 1 5,173 Dec-11-2019, 06:37 AM
Last Post: Malt
  Python-selenium script for automated web-login does not work hectorKJ 2 4,044 Sep-10-2019, 01:29 PM
Last Post: buran
  Python Selenium getting table element trengan 2 8,555 Dec-31-2018, 03:02 PM
Last Post: trengan
  Click Element if displayed using Selenium and Python giaco__mar 1 3,527 Dec-27-2018, 06:19 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020