简体   繁体   English

ElementNotInteractableException:消息:元素不是元素不可交互错误使用 Selenium 和 Python 将文本发送到 Email 字段

[英]ElementNotInteractableException: Message: element not element not interactable error sending text to Email field using Selenium and Python

I have tried all the posts with the same question from others but none of them worked for my case.我已经尝试过其他人提出相同问题的所有帖子,但没有一个适合我的情况。 I need to write a script to get wholesale prices for the website below:我需要编写一个脚本来获取以下网站的批发价格:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException

LoginURL = "https://www.coffeeparts.com.au/customer/account/login/"

driver = webdriver.Chrome("C:/chromedriver.exe")
driver.delete_all_cookies()

driver.get(LoginURL)

email = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, 'email')))
email.send_keys("test")

driver.close()

For any versions of the code I tried, I always get the same error.对于我尝试过的任何版本的代码,我总是会遇到同样的错误。 I need to run the send_keys method to both email and password fields, then click the login button.我需要对 email 和密码字段运行 send_keys 方法,然后单击登录按钮。 After then, I will get the login session information to run web scraper scripts for getting wholesale prices of the items.之后,我将获取登录 session 信息以运行 web 刮板脚本以获取商品的批发价格。

---------------------------------------------------------------------------
ElementNotInteractableException           Traceback (most recent call last)
<ipython-input-14-ee71e5f9bc26> in <module>()
     13 
     14 email = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, 'email')))
---> 15 email.send_keys("test")
     16 
     17 driver.close()

c:\python27\lib\site-packages\selenium\webdriver\remote\webelement.pyc in send_keys(self, *value)
    477         self._execute(Command.SEND_KEYS_TO_ELEMENT,
    478                       {'text': "".join(keys_to_typing(value)),
--> 479                        'value': keys_to_typing(value)})
    480 
    481     # RenderedWebElement Items

c:\python27\lib\site-packages\selenium\webdriver\remote\webelement.pyc in _execute(self, command, params)
    631             params = {}
    632         params['id'] = self._id
--> 633         return self._parent.execute(command, params)
    634 
    635     def find_element(self, by=By.ID, value=None):

c:\python27\lib\site-packages\selenium\webdriver\remote\webdriver.pyc in execute(self, driver_command, params)
    319         response = self.command_executor.execute(driver_command, params)
    320         if response:
--> 321             self.error_handler.check_response(response)
    322             response['value'] = self._unwrap_value(
    323                 response.get('value', None))

c:\python27\lib\site-packages\selenium\webdriver\remote\errorhandler.pyc in check_response(self, response)
    240                 alert_text = value['alert'].get('text')
    241             raise exception_class(message, screen, stacktrace, alert_text)
--> 242         raise exception_class(message, screen, stacktrace)
    243 
    244     def _value_or_default(self, obj, key, default):

ElementNotInteractableException: Message: element not interactable

Please help.请帮忙。 Thank you very much.非常感谢。

You were close.你很亲密。 But the locators you were using were identifying the Email Address field of the wholesale-login-form , instead you need to identify the Email Address field of login-form但是您使用的定位器正在识别wholesale-login-form的 Email地址字段,而不是您需要识别login-formEmail 地址字段


Solution解决方案

To send a character sequence to the Email Address field you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies :要将字符序列发送到Email 地址字段,您必须为element_to_be_clickable()引入WebDriverWait ,并且可以使用以下任一定位器策略

  • Using CSS_SELECTOR使用CSS_SELECTOR

     driver.get("https://www.coffeeparts.com.au/customer/account/login/") WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "form#login-form ul.form-list input#email"))).send_keys("vietnguyenswin")
  • Using XPATH :使用XPATH

     driver.get("https://www.coffeeparts.com.au/customer/account/login/") WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//h2[text()='Registered Customers']//following::ul[1]//input[@id='email']"))).send_keys("vietnguyenswin")
  • Note : You have to add the following imports:注意:您必须添加以下导入:

     from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
  • Browser Snapshot:浏览器快照:

咖啡零件


References参考

You can find a couple of relevant discussions in:您可以在以下位置找到一些相关的讨论:

Thank you everyone, I still would love to know how you can do that with Selenium.谢谢大家,我仍然很想知道如何使用 Selenium 做到这一点。 I solved the problem for getting the wholesale price by using different method:我通过使用不同的方法解决了获取批发价格的问题:

s = requests.Session()

Then I pass the cookies to the get method:然后我将 cookies 传递给 get 方法:

req = s.get(URL, cookies=cookies, headers=headers)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ElementNotInteractableException:消息:使用 Selenium 和 Python 将文本发送到 Quora 上的电子邮件字段时,元素不可交互错误 - ElementNotInteractableException: Message: element not interactable error while sending text to Email field on Quora using Selenium with Python ElementNotInteractableException:消息:使用 Selenium Python 在搜索字段中发送文本的元素不可交互错误 - ElementNotInteractableException: Message: element not interactable error sending text in search field using Selenium Python ElementNotInteractableException:元素不可交互错误将文本发送到电子邮件字段 - ElementNotInteractableException: element not interactable error sending text to Email field ElementNotInteractableException:消息:使用 Selenium 和 Python 向输入字段发送文本时键盘错误无法访问元素 - ElementNotInteractableException: Message: Element is not reachable by keyboard error sending text to input field using Selenium and Python Python selenium ElementNotInteractableException:消息:元素不可交互 - Python selenium ElementNotInteractableException: Message: element not interactable Python 中的 Selenium:ElementNotInteractableException:消息:元素不可交互 - Selenium in Python: ElementNotInteractableException: Message: element not interactable selenium.common.exceptions.ElementNotInteractableException:消息:将文本发送到 contenteditable div 元素时元素不可交互 - selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable while sending text to contenteditable div element ElementNotInteractableException:元素在 Selenium 中不可交互 - ElementNotInteractableException: element not interactable in Selenium 错误是“selenium.common.exceptions.ElementNotInteractableException:消息:元素不可交互” - error is “selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable” ElementNotInteractableException:消息:元素不可交互 - ElementNotInteractableException: Message: element not interactable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM