-1

I am having an issue with the code, it returns

TypeError: 'str' object is not callable

email = driver.find_element(By.ID("email-input")).getAttribute("id")

I read through some other threads and tried

email = driver.find_element(By.ID("email-input")).text

But it's not working

ERROR

Traceback (most recent call last): File "C:\Users\user\Desktop\LAB AUTOMATION\LAB.py", line 42, in email = driver.find_element(By.ID, "email-input").getAttribute("id") File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 855, in find_element return self.execute(Command.FIND_ELEMENT, { File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 428, in execute self.error_handler.check_response(response)

codester_09
  • 5,622
  • 2
  • 5
  • 27
  • 1
    Can you show the full [traceback](https://stackoverflow.com/questions/61335714/what-is-traceback-in-python) error? – codester_09 Sep 29 '22 at 02:22
  • Traceback (most recent call last): File "C:\Users\user\Desktop\LAB AUTOMATION\LAB.py", line 42, in email = driver.find_element(By.ID, "email-input").getAttribute("id") File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 855, in find_element return self.execute(Command.FIND_ELEMENT, { File "C:\Users\\user\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 428, in execute self.error_handler.check_response(response) – Syed Asad Haider Sep 29 '22 at 22:11
  • File "C:\Users\Syed\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="email-input"]"} (Session info: chrome=105.0.5195.127) Stacktrace: Backtrace: Ordinal0 [0x00FDDF13+2219795] Ordinal0 [0x00F72841+1779777] Ordinal0 [0x00E8423D+803389] Ordinal0 [0x00EB3025+995365] Ordinal0 [0x00EB31EB+995819] – Syed Asad Haider Sep 29 '22 at 22:12
  • Welcome to Stack Overflow. Please show a [complete](https://meta.stackoverflow.com/questions/359146) error message by the following steps: 1. [edit] the question. 2. **copy and paste**, starting from the line that says `Traceback (most recent call last):` **until the end, including** the line that says `TypeError`, into the post. 3. Put three backticks, **on a separate line**, **above and below** the pasted error message. Do not use the comments to show an error message, and make sure the error is properly formatted in the post. – Karl Knechtel Sep 30 '22 at 03:16

1 Answers1

0

find_element takes a type string plus additional parameters based on type. By.ID is just the string "id". You want to use 2 parameters. The first flags that you are finding by id, and the second is the id to be found.

email = driver.find_element(By.ID, "email-input").getAttribute("id")

See Locating Elements for more details on locating elements.

tdelaney
  • 73,364
  • 6
  • 83
  • 116
  • I tried that too but got this error : selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="email-input"]"} – Syed Asad Haider Sep 29 '22 at 04:28
  • @SyedAsadHaider - I don't have your data but the error suggests that you don't have an element with that id. – tdelaney Sep 29 '22 at 05:17
  • 1
  • Here is the element – Syed Asad Haider Sep 29 '22 at 05:41
  • That is a new problem, and demands a new question. Make sure to follow all the steps (read [ask], [mre], https://ericlippert.com/2014/03/05/how-to-debug-small-programs/ and https://meta.stackoverflow.com/questions/261592 first in order to understand how to ask questions properly) before asking. Note well that Stack Overflow is **not a discussion forum**. Posts here are **not** for the purpose of getting the problem with your code fixed; they are for the purpose of building a searchable Q&A library, as described in the [tour]. – Karl Knechtel Sep 30 '22 at 03:19