简体   繁体   English

ElementNotInteractableException:消息:使用 Selenium 和 Python 将文本发送到 Quora 上的电子邮件字段时,元素不可交互错误

[英]ElementNotInteractableException: Message: element not interactable error while sending text to Email field on Quora using Selenium with Python

Here is my code:这是我的代码:

from selenium import webdriver

user = "someemail@email.com"

browser = webdriver.Chrome("/path/to/browser/")

browser.get("https://www.quora.com/")

username = browser.find_element_by_name("email")

browser.implicitly_wait(10)

username.send_keys(user)

Here is the error message:这是错误消息:

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

I think there is another thread with a similar issue.我认为还有另一个线程有类似的问题。 Either the solutions in that thread didn't work for me or I don't know how to implement the solutions.该线程中的解决方案对我不起作用,或者我不知道如何实施这些解决方案。

find_element_by_name("email")

is present multiple times in DOM.在 DOM 中多次出现。 So that wouldn't work.所以那行不通。

You can try with this css selector :您可以尝试使用此css 选择器

input[class*='header_login_text_box'][name='email']  

Code :代码 :

username = browser.find_element_by_css_selector("input[class*='header_login_text_box'][name='email']")

username.send_keys("user@gmail.com")

To send a character sequence to the Email field within Login section of Quora you need to induce WebDriverWait for the element to be clickable and you can use the following solution:要将字符序列发送到Quora登录部分中的电子邮件字段,您需要引入WebDriverWait以使元素可点击,您可以使用以下解决方案:

  • Code Block:代码块:

     from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC options = webdriver.ChromeOptions() options.add_argument("start-maximized") options.add_argument("--disable-extensions") # options.add_argument('disable-infobars') driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\\Utility\\BrowserDrivers\\chromedriver.exe') driver.get("https://www.quora.com/") WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='title login_title' and text()='Login']//following::div[1]//input[@class='text header_login_text_box ignore_interaction']"))).send_keys("someemail@email.com")
  • Browser Snapshot:浏览器快照:

quora_email

As said in comment, the locator used returning two elements and required element is second one.正如评论中所说,定位器使用返回两个元素,所需元素是第二个。 driver trying to interact with first element, so exception is throwing.驱动程序试图与第一个元素进行交互,因此抛出异常。

good see in console, the locator returning required one or not.好在控制台中看到,返回的定位器是否需要一个。

> $$("[name='email']") (2) [input#__w2_wD9e9Qgz12_email.text, input#__w2_wD9e9Qgz18_email.text.header_login_text_box.ignore_interaction]
> 0: input#__w2_wD9e9Qgz12_email.text 1:
> input#__w2_wD9e9Qgz18_email.text.header_login_text_box.ignore_interaction
> length: 2
> __proto__: Array(0)

go for another locator, if not able to figure it out another locator, then comment, will help you.去寻找另一个定位器,如果无法弄清楚另一个定位器,那么评论,会帮助你。

from selenium import webdriver

user = "someemail@email.com"

browser = webdriver.Chrome("/path/to/browser/")

browser.get("https://www.quora.com/")

username = browser.find_element_by_xpath("//input[@class='text header_login_text_box ignore_interaction' and @type='text']")

browser.implicitly_wait(10)

username.send_keys(user)

Here You can find Why ElementNotInteractableException occurs.在这里你可以找到为什么ElementNotInteractableException发生。

If you are using the Select aproach like:如果您使用的是Select例如:

from selenium.webdriver.support.select import Select

try this尝试这个

Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '''//*[@id="ReportViewer1_ctl04_ctl07_ddValue"]''')))).select_by_visible_text(str(x))

暂无
暂无

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

相关问题 ElementNotInteractableException:消息:元素不是元素不可交互错误使用 Selenium 和 Python 将文本发送到 Email 字段 - ElementNotInteractableException: Message: element not element not interactable error sending text to Email field using Selenium and 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 selenium.common.exceptions.ElementNotInteractableException:消息:将文本发送到 contenteditable div 元素时元素不可交互 - selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable while sending text to contenteditable div element selenium.common.exceptions.ElementNotInteractableException:消息:使用Selenium和Python插入值时元素不可交互 - selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable while inserting value 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 ElementNotInteractableException:尝试使用 Selenium 和 Python 在 www.finanzen.net 上搜索股票时出现元素不可交互错误 - ElementNotInteractableException: element not interactable error while trying to search for stock on www.finanzen.net using Selenium and Python 错误是“selenium.common.exceptions.ElementNotInteractableException:消息:元素不可交互” - error is “selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM