首页 > 解决方案 > 元素不可交互的硒python3.9

问题描述

我尝试使用 Selenium 自动登录到该站点,在其他站点上一切正常。当我尝试在该字段中输入我的用户名时遇到错误:

File "C:\Users\BOY4ik\PycharmProjects\pythonProject\main.py", line 17, in <module>
    input_login.send_keys('u.t.x.c.x.z.2.9.0@gmail.com')
  File "C:\Users\BOY4ik\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 477, in send_keys
    self._execute(Command.SEND_KEYS_TO_ELEMENT,
  File "C:\Users\BOY4ik\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "C:\Users\BOY4ik\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\BOY4ik\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
  (Session info: chrome=91.0.4472.101)

链接:https ://all-access.wax.io/

我的代码

browser = webdriver.Chrome()
browser.get('https://all-access.wax.io/')
time.sleep(2)
input_login = browser.find_element_by_xpath('/html/body/div[1]/div/div/div[2]/div[5]/div/div/div/div[1]/div[1]/input')
browser.execute_script("arguments[0].click();", input_login)
input_login.send_keys('LOGIN')
input_pass = browser.find_element_by_xpath('/html/body/div[1]/div/div/div[2]/div[5]/div/div/div/div[1]/div[2]/input')
input_pass.send_keys('PASS')
time.sleep(30)
sign_up=browser.find_element_by_xpath('/html/body/div[1]/div/div/div[2]/div[5]/div/div/div/div[5]/button[2]')
sign_up.click()
time.sleep(1)
browser.switch_to.window(browser.window_handles[0])

标签: pythonselenium

解决方案


好的下面的解决方案假设 OP 可以处理captcha使用AntiCaptcha.

wait = WebDriverWait(driver, 10)
driver.get("https://all-access.wax.io")
wait.until(EC.element_to_be_clickable((By.NAME, "userName"))).send_keys("Login user name here")
wait.until(EC.element_to_be_clickable((By.NAME, "password"))).send_keys("Login password here")

并且 OP 将在这里处理验证码:

然后像这样点击登录按钮:

ActionChains(driver).move_to_element(wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Login']")))).click().perform()

进口:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains

推荐阅读