Why am I getting 'NoneType' object has no attribute 'sendkeys' error in Python 3.11.3 Selenium automation with Chrome 113.0.5672.127?

huangapple go评论74阅读模式
英文:

Why am I getting 'NoneType' object has no attribute 'sendkeys' error in Python 3.11.3 Selenium automation with Chrome 113.0.5672.127?

问题

I am using selenium 4.9.1, Chrome Version 113.0.5672.127 (Official Build) (64-bit)
python 3.11.3, I am trying to run a selenium function which uses sendkeys():

Error: Traceback (most recent call last):
  File "C:\Users\DELL PC\PycharmProjects\salmanpythontest\new.py", line 10, in <module>
    driver.find_element_by_id("email").sendkeys("abc@gmaail.com")
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'sendkeys'

code screen shot with error

I am trying to login in a module

英文:

I am using selenium 4.9.1, Chrome Version 113.0.5672.127 (Official Build) (64-bit)
python 3.11.3, I am trying to run a selenium function which uses sendkeys():

Error: Traceback (most recent call last):
  File &quot;C:\Users\DELL PC\PycharmProjects\salmanpythontest\new.py&quot;, line 10, in &lt;module&gt;
    driver.find_element_by_id(&quot;email&quot;).sendkeys(&quot;abc@gmaail.com&quot;)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: &#39;NoneType&#39; object has no attribute &#39;sendkeys&#39;

code screen shot with error

I am trying to login in a module

答案1

得分: 0

"The error message you encountered, 'AttributeError: 'NoneType' object has no attribute 'sendkeys',' indicates that you are trying to use the send_keys method from the Selenium library on a variable or object of type None. This error typically occurs when the object you are trying to interact with using Selenium has not been found or initialised correctly.

Ensure that the 'email' is the right locator id you are using.

I have visited the URL, seems like the id of the locator should be 'testing' not 'email'.

Look at the DOM here

英文:

The error message you encountered, "AttributeError: 'NoneType' object has no attribute 'sendkeys'," indicates that you are trying to use the send_keys method from the Selenium library on a variable or object of type None.
This error typically occurs when the object you are trying to interact with using Selenium has not been found or initialised correctly.

Ensure that the "email" is the right locator id you are using.

I have visited the URL, seems like the id of the locator should be "testing" not "email".

Look at the DOM here

答案2

得分: 0

find_element_by_id - 这个方法已经在selenium v4.3.0及更高版本中被弃用和移除。

由于您正在使用selenium v4.9.1,您应该使用这个方法 find_element 来替代。

所以,请将下面的代码行进行替换:

driver.find_element_by_id("email").sendkeys("abc@g.com")

替换为:

driver.find_element(By.ID, "email").send_keys("abc@gmail.com")

您需要以下导入:

from selenium.webdriver.common.by import By
英文:

find_element_by_id - This method has been deprecated and removed from selenium v4.3.0 and onwards.

Since you are using selenium v4.9.1, you should use this method find_element instead.

So, replace the below line of code:

driver.find_element_by_id(&quot;email&quot;).sendkeys(&quot;abc@g.com&quot;)

To:

driver.find_element(By.ID, &quot;email&quot;).send_keys(&quot;abc@gmail.com&quot;)

You will need below import:

from selenium.webdriver.common.by import By

huangapple
  • 本文由 发表于 2023年5月22日 01:38:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76301156.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定