python - 元素不可交互的硒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])
解决方案
好的下面的解决方案假设 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
推荐阅读
- python - Python - 允许更改设置文件?
- bash - 是否有像 `seq` 这样的命令,它对标准输出执行完整的类似 bash 的大括号扩展?
- sql - 将不同列中的值移动到一行
- sorting - 在 2 列上使用 uniq 时,如何将第三列的值合并到 linux 中的一个单元格中并计算 uniq 实例的数量?
- python - 将 PSD 保存为 JPG,没有不可见的图层
- grafana - 基于另一个元素 Y 更改元素 X 的数据
- java - 发布请求返回 - java.io.IOException:com.android.okhttp.Address 上的流意外结束
- python - Mac 上的 Selenium ChromeDriver 让我退出帐户
- kotlin - activeNetworkInfo 和 isConnected 被划掉
- node.js - 使用 gmail api 过滤掉某种格式的电子邮件