我尝试使用python和selenium将文本输入到输入字段中,但我收到一个错误,告诉我-〉消息:元素不可交互
下面是失败的代码:
webdriver.ActionChains(self.driver).send_keys(Keys.TAB).perform()
webdriver.ActionChains(self.driver).send_keys(Keys.TAB).perform()
time.sleep(15)
WebDriverWait(self.driver, 15).until(EC.presence_of_element_located((By.XPATH, "//span[contains(@class, 'input-container')]"))).send_keys("test")
这个元素有一个类名input-container,我试图用标签导航到它,然后把“test”放进去。在此之前我也试着点击它,得到了同样的错误。下面是代码:
WebDriverWait( self.driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//span[contains(@class,'input-container')]"))).click()
time.sleep(15)
WebDriverWait(self.driver, 15).until(EC.presence_of_element_located((By.XPATH, "//span[contains(@class, 'input-container')]"))).send_keys("test")
我添加了sleep,以查看我是否真的被点击到了文本字段上,并且我仍然收到了这个错误。完整的堆栈跟踪如下所示:
Traceback (most recent call last):
File "/Users/user1/Desktop/btm.py", line 124, in <module>
b.begin()
File "/Users/user1/Desktop/btm.py", line 80, in begin
WebDriverWait(self.driver, 15).until(EC.presence_of_element_located((By.XPATH,
"//span[contains(@class, 'input-container')]"))).send_keys("test")
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-
packages/selenium/webdriver/remote/webelement.py", line 233, in send_keys
self._execute(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-
packages/selenium/webdriver/remote/webelement.py", line 410, in _execute
return self._parent.execute(command, params)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-
packages/selenium/webdriver/remote/webdriver.py", line 444, in execute
self.error_handler.check_response(response)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-
packages/selenium/webdriver/remote/errorhandler.py", line 249, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not
interactable
(Session info: chrome=108.0.5359.98)
input元素如下所示
<span class="input-container span-to-div"><input aria-label="Blank 1 of 1" autocapitalize="off" autocomplete="new-password" autocorrect="off" class="fitb-input " id="fitbTesting_eebce337-d24b-4253-82cd-878f339bf49b" maxlength="50" name="fitbTesting_4bfacf11-846f-48c8-9821-f276b3ef43b8" spellcheck="false" value=""><span aria-label="Empty Blank 1 of 1" class="_visuallyHidden"></span></span>
这是在我尝试将“test”发送到输入之前的15秒内屏幕的外观
如果我遗漏了任何必要的信息,请让我知道,我会很乐意添加到我的职位!
1条答案
按热度按时间4ioopgfo1#
找到了解决方案。我试图将输入传递给一个span,而不是实际的input标记本身
我的代码的更新版本可以在这里工作:
其中x和aria-label是表示当前输入(x)和输入总量(aria_label)的整数