【问题标题】:element not interactable selenium python3.9元素不可交互的硒python3.9
【发布时间】:2021-06-12 12:04:12
【问题描述】:

我尝试使用 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])

【问题讨论】:

  • 我看到有一个验证码,你能处理吗?
  • @cruisepandey 是的,使用扩展 AntiCaptcha
  • 查看下面的代码。

标签: python selenium


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-06
    • 2019-09-30
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    • 2021-06-30
    相关资源
    最近更新 更多